[Python-ideas] a new lambda syntax
steve at pearwood.info
Fri Oct 23 04:30:46 CEST 2009
On Thu, 22 Oct 2009 07:49:14 pm Sturla Molden wrote:
> If that is not allowed then, an anynymous block cannot be called or
> referenced, as there are no name associated with it.
That is clearly wrong. You don't need a name to call an object. You just
need the object.
>>> (lambda x: x+1)(42)
>>> [None, lambda s: s.upper(), None]('abc')
> 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:
That doesn't even make sense to me. I don't understand what the
decorator is doing there, or how it helps you access the anonymous
function. Under today's semantics (modified to allow anonymous def),
that would create an anonymous function containing <suite>, then pass
that function to decorator(), and treat the return result as anonymous.
Since you're not keeping a reference to the anonymous function, it will
then be garbage collected. Passing it into a decorator first won't
change that (unless the decorator stores the function somewhere as a
In other words, the above is just like this:
which is legal but pointless unless you do something with the result.
> Now we can see that the use for this anonymous block "def()" simply
> goes away, as it too is redundant syntax.
Why? Functions aren't the only thing you can apply decorators to. You
can also call:
in Python 2.6 and better.
More information about the Python-ideas