Draft Pep (was: Re: Let's Talk About Lambda Functions!)

Bryan Olson fakeaddress at nowhere.org
Mon Aug 5 12:18:34 EDT 2002


John Roth wrote:

>>Contrary to popular belief, lambda did not add anoymous functions to
>>Python.  Python had them even without lambda.
>>
>>def define_twice():
>>     def _twice(x):
>>         return x + x
>>     return _twice
>>
>>print define_twice()(17)
>>
>>The above code passes 17 to a function which is not bound to any name.
> 
> 
> It is bound to a name. Specifically, it's bound to _twice. The
> fact that the name is part of the function's scope, and not the
> enclosing class or module scope doesn't make it not a name!

Check the rules on local variables.  The function was, at one
time, bound to the name _twice.  Nevertheless, the above code
passes 17 to a function that is not bound to any name.


--Bryan




More information about the Python-list mailing list