[Python-Dev] any support for a methodcaller HOF?

Bengt Richter bokr at oz.net
Fri Feb 3 21:58:06 CET 2006

On Fri, 03 Feb 2006 19:10:42 +0100, Christian Tismer <tismer at stackless.com> wrote:

>Bengt Richter wrote:
>> BTW, re def-time bindings, the default arg abuse is a hack, so I would like to
>> see a syntax that would permit default-arg-like def-time function-local bindings without
>> affecting the call signature. E.g., if def foo(*args, **keywords, ***bindings): ...
>> would use bindings as a dict at def-time to create local namespace bindings like **keywords,
>> but not affecting the call signature. This would allow a nicer version of above-mentioned
>>    lambda x, zip=zip, zop=zop:x.method(zip,zop)
>> as
>>    lambda x, ***dict(zip=zip, zop=zop):x.method(zip,zop)
>> or
>>    lambda x, ***{'zip':zip, 'zop':zop}:x.method(zip,zop)
>> This could also be used to do currying without the typical cost of wrapped nested calling.
>Just in case that you might be not aware of it (like I was):
>lambda does support local scope, like here:
> >>> def locallambda(x, y):
>... 	func = lambda: x+y
>... 	return func
> >>> f=locallambda(2, 3)
> >>> f()
Yes, thanks, I really did know that ;-/ Just got thinking along another line. So
    lambda x, zip=zip, zop=zop:x.method(zip,zop)
    lambda x, ***{'zip':zip, 'zop':zop}:x.method(zip,zop)
would better have been
    (lambda zip,zop:lambda x:x.method(zip,zop))(zip, zop)

Bengt Richter

More information about the Python-Dev mailing list