List comprehension confusion...

Alexander Schmolck a.schmolck at gmx.net
Mon Feb 10 20:35:04 EST 2003


kaz at ashi.footprints.net (Kaz Kylheku) writes:

> In other words, the limitation which prevents a lambda body from
> having the full expressivity of the body of an ordinary named function
> is so wonderful, that it's in fact your ONLY reason for using lambda.
> 
> Classic rationalization at work. ``Not only is the car I just bought
> the best possible car I could have bought, but I like it *precisely*
> because it can't go over 35 km/h.'' Do a web search for ``cognitive
> dissonance''.

Have you got a good reason why you want anonymous functions with full
expressivness in python? At least the limitation means you get a (sort of)
lightweight function notation; I'd rather write 

  lambda : 1

then

  lambda : return 1

> 
> I have news for you: other people use lambdas because they want an
> anonymous function that captures the lexical environment. There are

I have the vague feeling that you don't understand that you don't need lambdas
for closures.

def foo(a):
   def bar(): return a
   return bar
>>> foo(1)()
1

If that vague feeling is wrong, could you maybe explain why you feel the need
to use an anonymous function to close over a variable (in a language without
macros)?


alex




More information about the Python-list mailing list