1 | initial version |
The following example illustrates the problem Niles saw with using lambda. Notice that the t in the lambda is taken from the current value of t in the global scope:
sage: f=lambda x: (x,t)
sage: t=2
sage: f(1)
(1, 2)
sage: t=3
sage: f(1)
(1, 3)
sage:
See the first few answers of http://stackoverflow.com/questions/938429/scope-of-python-lambda-functions-and-their-parameters for more discussion.
2 | No.2 Revision |
The following example illustrates the problem Niles saw with using lambda. Notice that the t in the lambda is taken from the current value of t in the global scope:
sage: f=lambda x: (x,t)
sage: t=2
sage: f(1)
(1, 2)
sage: t=3
sage: f(1)
(1, 3)
sage:
See the first few answers of http://stackoverflow.com/questions/938429/scope-of-python-lambda-functions-and-their-parameters for more discussion.discussion. Here is one workaround from those answers:
sage: f=lambda x,t=t: (x,t)
sage: t=1
sage: f(1)
(1, 100)