You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2005-10-14.14:41:44.000>created_at=<Date2005-10-13.20:56:32.000>labels= ['interpreter-core', 'invalid']
title='odd behaviour when making lists of lambda forms'updated_at=<Date2005-10-14.14:41:44.000>user='https://bugs.python.org/jhidding'
I don't know if this is really a bug, but it is odd. I
tried to make a list of lambda forms like in the
following example, but the functions thus created don't
really do what I expect.
**************
Python 2.3.5 (#2, Jun 19 2005, 13:28:00)
[GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> p = [lambdat: t**n for n inrange(6)]
>>> p[0](2)
32
>>> p
[<function <lambda> at 0xb7cece64>, <function <lambda>
at 0xb7cf10d4>, <function <lambda> at 0xb7cf1b1c>,
<function <lambda> at 0xb7cf1b54>, <function <lambda>
at 0xb7cf1b8c>, <function <lambda> at 0xb7cf1bc4>]
>>> p[1](2)
32
>>> p[1](5)
3125
****************
While:
****************
>>> q = [lambdat: 1, lambdat: t, lambdat: t**2,
lambda t: t**3, lambda t: t**4]
>>> q[0](4)
1
>>> q[1](4)
4
>>> q[2](4)
16
***************
I tried creating the list using a for loop, but it
shows the same weird behaviour. Also any attempt to put
the lambda form in an object didn't give a cure.
say:
Wrap(lambda x: x**2)
creates a callable object storing the lambda form as a
data member.
****
>>> j = [Wrap(lambdat: t**n) for n inrange(5)]
>>> j[0](1)
1
>>> j[0](3)
81
>>> j[0](5)
625
****
Both Python 2.3 and 2.4 show this behaviour. Am I
completely overlooking something, or...?
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: