Lambda going out of fashion

Stephen Thorne stephen.thorne at gmail.com
Thu Dec 23 05:47:29 EST 2004


On 23 Dec 2004 00:52:53 -0800, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> Alan Gauld <alan.gauld at btinternet.com> writes:
> > readability. Pythonic lambdas are just syntactic sugar in
> > practice,
> 
> Actually it's the other way around: it's named functions that are the
> syntactic sugar.

Not true, you can't re-write

def f():
    raise ValueError, "Don't call f"

as a lambda. Lambdas contain only a single expression. Even the py3k
wiki page ignores this critical difference. A single expression means
no statements of any kind can be included. Assignment, if/elif/else,
while, for, try/except, etc are not catered for in lambdas.

There has been a case in the past for a lambda that contains
statements, but they have been stomped on due to problems with syntax.
I don't like lambdas that have more than a single expression myself
(if it's more complex than "lambda x:baz(x.foo(y))", I would prefer to
write a named function).

ultimate-ly yr's.
Stephen Thorne.



More information about the Python-list mailing list