Is this a good use for lambda

Simo Melenius firstname.lastname at
Sun Dec 19 22:29:42 CET 2004

"Fredrik Lundh" <fredrik at> writes:

> Walter S. Leipold wrote:
> > I think that Charlie's point is that, when you use "def <name>",
> > you have <name> polluting your namespace. The whole program
> > becomes harder to understand because you can't ignore <name>
> > anywhere, even if it was only ever intended to be used in one
> > place.
> Ahem. If you name the function, you can reuse the name (or just
> forget about it) as soon as you've used the function object.

Sure, but mental pollution counts too IMO. What you write and what you
read must go through your brain, including dummy variables. And next
you start thinking how to "hide" it from your own mind (e.g. naming it
"_my_local_func" or something as ugly as the leading underscores in

And I think that it does, in fact, touch the innermost symbol table
too, even if the case is optimized out by the compiler -- is it?

Why do something for the sake of not actually having to do it?


Anyway, personally, this namespace cluttering most often happens
because lambda is only a single expression. If one could write a true
function block into a lambda, there would be less cases where lambda
doesn't suffice, really.

Now, if lambda was more than an expr, dumping "lambda" keyword would
be a convenient idea -- unnecessary keywords can make the language
less clear in some cases. One could do with Python's plain and simple
"def", like this:

filter (def (x): x*2, myseq)

(Disclaimer: Without thinking further I'm not sure whether the above
syntax would be unique enough, Python grammar-wise.)


More information about the Python-list mailing list