[Python-Dev] Let's just *keep* lambda

Jiwon Seo seojiwon at gmail.com
Thu Feb 9 10:51:58 CET 2006

On 2/8/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> Jiwon Seo wrote:
> > Then, is there any chance anonymous function - or closure - is
> > supported in python 3.0 ? Or at least have a discussion about it?
> That discussion appears to be closed (or, not really: everybody
> can discuss, but it likely won't change anything).
> > (IMHO, closure is very handy for function like map, sort etc. And
> > having to write a function for multiple statement is kind of good in
> > that function name explains what it does. However, I sometimes feel
> > that having no name at all is clearer. Also, having to define a
> > function when it'll be used only once seemed inappropriate sometimes.)
> Hmm. Can you give real-world examples (of existing code) where you
> needed this?

Apparently, simplest example is,

collection.visit(lambda x: print x)

which currently is not possible. Another example is,

map(lambda x: if odd(x): return 1
                      else: return 0,

(however, with new if/else expression, that's not so much a problem any more.)

Also, anything with exception handling code can't be without explicit
function definition.

collection.visit(lambda x: try: foo(x); except SomeError: error("error

Anyway, I was just curious that if anyone is interested in having more
closure-like closure in python 3.0 - in any form, not necessary an
extension on lambda.


> Regards,
> Martin

More information about the Python-Dev mailing list