LAMBDA IS IT USELESS?
aleaxit at yahoo.com
Sat Jul 14 10:48:43 CEST 2001
"Bengt Richter" <bokr at accessone.com> wrote in message
news:3b4f6eb5.1832748462 at wa.news.verio.net...
> On Fri, 13 Jul 2001 18:01:37 +0200, "Alex Martelli" <aleaxit at yahoo.com>
> >or to the def. The ONLY difference is that lambda generates an
> >anonymous function (and is an expression), while def generates a
> >named function (and is a statement).
> In that case why not allow an anonymous version of def, e.g..,
> which would work like
> lambda x:x**2
Judging from this sole example, the only difference here would
be the inconsequential syntax sugar of WRITING def(x) vs
lambda x -- who cares for such trifles?
Very different would be if the def was still a statement (and
particularly a compound statement, including other statements):
in that case, its anonimity would be no use UNLESS one fundamental
principle of Python syntax was abrogated -- no expression can
include statements. If that were done, then there would be very
wide-spread repercussions, needing a careful redesign of many
> (OTOH you could make lambda multi-line ;-)
lambda can be multi-line today. I.e., you're free to break the
line after the ':' in the above example. Lines are not an issue.
STATEMENTS vs EXPRESSIONS is the issue.
More information about the Python-list