Re: Python had a little lambda ...

Tim Peters (tim@ksr.com)
Wed, 23 Feb 94 20:47:23 EST

> [steve]
> The Python syntax is:
> lambda <parameters> : <expression>
>
> as in:
> >>>plus1 = lambda x : x+1
> >>>plus1( 2 )
> 3
> or:
> >>>map( lambda x,y : x + y, range( 0, 10 ), [ 10 ] * 10 )
> [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

And semantically,

... lambda <parameters> : <expression> ...

acts as if this had been written instead:

def a_unique_name( <parameters> ):
return <expression>
... a_unique_name ...

> ...
> Tim said [lambda] was in the FAQ, but I didn't grep it.
> Maybe he meant the NEWS file.

No, lambda isn't in the FAQ; FAQ question 4.5 is "why can't a nested
function access the local variables of the outer function"? Because of
the semantic model above, that's a supremely relevant question. A full
explanation of namespaces is in 4.1 of the language reference manual.

> [ xrange is also mentioned in the Misc/NEWS file, but I didn't
> see any mention of it in the library manual. ]

grep'ing the doc .tex files for "xrange" strikes out.

efficiently y'rs - tim

Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp