Message24412
Logged In: YES
user_id=432579
>Variables in Python functions are resolved
>when the function is *called*, not when it is defined.
I'm not sure what you mean by that, since Python obeys
lexical scoping, not dynamic.Consider:
def f(x): lambda y: x + y
When the inner lambda expression above is evaluated, x
inside the lambda body is bound to the parameter of the call
of f, even if x+y is not evaluated until that function is
called.
So since
def f(x): return eval('x')
fetches its definition of x from the lexical variable x, why
shouldn't
def f(g): return eval('lambda x: g(x)')
fetch its definition of g from the lexical variable g? A
lambda expression is just a way of delaying evaluation,
*not* delaying how variables are bound --- this is done
immediately.
|
|
Date |
User |
Action |
Args |
2007-08-23 14:29:50 | admin | link | issue1153622 messages |
2007-08-23 14:29:50 | admin | create | |
|