[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():
<suite>
This could just as well be written:
def name():
<suite>
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:
@decorator
def():
<suite>
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:
@decorator
<suite>
Since blocks do not create new scopes, I think the answer should be "no".
S.M.
More information about the Python-ideas
mailing list