Something is rotten in Denmark...
Terry Reedy
tjreedy at udel.edu
Wed Jun 1 13:11:10 EDT 2011
On 5/31/2011 8:09 PM, harrismh777 wrote:
> At the moment I'm only speaking about my OP and that particular list
> comprehension... the thing that happened (at least for me) is that the
> intuitive sense that each 'i' somehow becomes a part of the anonymous
> function (I know, not so) is built-in. There is little to nothing
> indicating in the docs that this is not so
On the contrary, the docs very explicitly say that a lambda expression
is equivalent to a def statement.
"[Lambda forms (lambda expressions)] are a shorthand to create anonymous
functions; the expression lambda arguments: expression yields a function
object. The unnamed object behaves like a function object defined with
def <lambda>(arguments):
return expression"
? Again, what we have here is
> the 'i' being saved in a cell and looked up at call time (an
> implementation detail, 'late-binding') that is critical for the
> user-coder to understand.
Again, exactly the same as if the function were created with a def
statement.
> I'm not commenting on that, but it seems to me that if lambda is going
> to remain in the language at all that 'early-binding' in the lambda
> specific case would make sense; at least make the lambda more useful
> generally.
I disagree. Currently, late-binding is the default, with early-binding
an option through a few different mechanisms. Making early binding the
default would *reduce* the usefulness by eliminating the late-binding
option and would add nothing that cannot be done now.
There are some people whose 'intuition' is the opposite of yours. They
instead want to eliminate the early-binding option of default argument
expressions. They want to reduce flexibility in the other direction.
Both proposals are equally bad.
--
Terry Jan Reedy
More information about the Python-list
mailing list