[Python-ideas] a new lambda syntax

Sturla Molden sturla at molden.no
Thu Oct 22 10:49:14 CEST 2009

Guido van Rossum skrev:
> I actually don't buy that argument. I believe that the main reason
> people keep arguing for anonymous blocks (and this will never stop) is
> simply that there is a certain segment of the programmer population
> that is used to solving a large variety of problems with anonymous
> blocks and that they don't want to learn how to solve each of those
> cases using the existing tools in Python.
I think anonymous blocks have proven their usefulness in concurrency 
programming. Just take a look at OpenMP or Apple's GCD. But I'll make an 
argument against anonymous blocks anyway:

We can create "anonymous" blocks by throw-away names like "def _()", but 
why clutter the scope with names that are never used? So assume we would 
allow write "def():" to designate an anonymous block. I think 99% would 
abuse it like this:

name = def():

This could just as well be written:

def name():

Thus, certainly "name = def():" should not be allowed.

If that is not allowed then, an anynymous block cannot be called or 
referenced, as there are no name associated with it. So to be useful, it 
would always have to be associated with a decorator.  That would be the 
only way to get access to it:


Now we can see that the use for this anonymous block "def()" simply goes 
away, as it too is redundant syntax.

Then it all comes down to whether or not allow decorators on code blocks:


Since blocks do not create new scopes, I think the answer should be "no".


More information about the Python-ideas mailing list