Securing a future for anonymous functions in Python
bokr at oz.net
Fri Jan 7 23:02:19 CET 2005
On 07 Jan 2005 14:38:01 +0100, Jacek Generowicz <jacek.generowicz at cern.ch> wrote:
>[*] Funnily enough, getting them to understand that "lambda x: fn(x)"
> is just a very silly way of writing "fn", can be quite a struggle
> at times ... but that's probably a consequence of the context in
> which lambda is introduced.
Actually, it may _usually_ be silly, but it could be a way of deferring
a name lookup instead of using the current binding of a name:
>>> def bar(): return 'this is bar'
>>> def foo(f=bar): print f()
>>> def bar(): return 'this is updated bar'
this is bar
>>> def foo(f=lambda:bar()): print f()
this is updated bar
>>> def bar(): return 'this updated bar was picked up by silly lambda'
this updated bar was picked up by silly lambda
More information about the Python-list