Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

odd behaviour when making lists of lambda forms #42480

Closed
jhidding mannequin opened this issue Oct 13, 2005 · 2 comments
Closed

odd behaviour when making lists of lambda forms #42480

jhidding mannequin opened this issue Oct 13, 2005 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@jhidding
Copy link
Mannequin

jhidding mannequin commented Oct 13, 2005

BPO 1326195
Nosy @rhettinger

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 = None
closed_at = <Date 2005-10-14.14:41:44.000>
created_at = <Date 2005-10-13.20:56:32.000>
labels = ['interpreter-core', 'invalid']
title = 'odd behaviour when making lists of lambda forms'
updated_at = <Date 2005-10-14.14:41:44.000>
user = 'https://bugs.python.org/jhidding'

bugs.python.org fields:

activity = <Date 2005-10-14.14:41:44.000>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2005-10-13.20:56:32.000>
creator = 'jhidding'
dependencies = []
files = []
hgrepos = []
issue_num = 1326195
keywords = []
message_count = 2.0
messages = ['26589', '26590']
nosy_count = 2.0
nosy_names = ['rhettinger', 'jhidding']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1326195'
versions = ['Python 2.3']

@jhidding
Copy link
Mannequin Author

jhidding mannequin commented Oct 13, 2005

Hi,

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 = [lambda t: t**n for n in range(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 = [lambda t: 1, lambda t: t, lambda t: 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(lambda t: t**n) for n in range(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...?

kind regards,

Johan Hidding
Groningen, the Netherlands

@jhidding jhidding mannequin closed this as completed Oct 13, 2005
@jhidding jhidding mannequin added invalid interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Oct 13, 2005
@jhidding jhidding mannequin closed this as completed Oct 13, 2005
@jhidding jhidding mannequin added invalid interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Oct 13, 2005
@rhettinger
Copy link
Contributor

Logged In: YES
user_id=80475

Try this:
p = [lambda t, n=n: t**n for n in range(6)]

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

1 participant