[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-04 Thread Ezio Melotti
Ezio Melotti added the comment: Fixed, thanks for the review! -- resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed ___ Python tracker ___ ___

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-04 Thread Roundup Robot
Roundup Robot added the comment: New changeset fdc894d44d82 by Ezio Melotti in branch '2.7': #13094: add Programming FAQ entry about the behavior of closures. http://hg.python.org/cpython/rev/fdc894d44d82 New changeset 02933454b7ce by Ezio Melotti in branch '3.2': #13094: add Programming FAQ ent

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-04 Thread R. David Murray
R. David Murray added the comment: Looks good to me. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-04 Thread Ezio Melotti
Ezio Melotti added the comment: Attached a new patch. -- Added file: http://bugs.python.org/file28563/issue13094-2.diff ___ Python tracker ___ ___

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-03 Thread Ezio Melotti
Changes by Ezio Melotti : -- assignee: -> ezio.melotti ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-03 Thread Ezio Melotti
Ezio Melotti added the comment: Here's a patch. -- keywords: +patch stage: needs patch -> patch review Added file: http://bugs.python.org/file28550/issue13094.diff ___ Python tracker ___

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-03 Thread R. David Murray
R. David Murray added the comment: The point is, it is a FAQ. We are talking about updating the FAQ document. It doesn't matter if the text is "too specific", if it is in fact a FAQ. And it is. -- ___ Python tracker

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-03 Thread Ezio Melotti
Ezio Melotti added the comment: > "why do the lambdas I define in a loop all return the same result when > the input value was different when each one was defined?" I thought about that, but that sounds a bit too long/specific. It also has the problem that the issue is not strictly related to

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-03 Thread R. David Murray
R. David Murray added the comment: The FAQ (as in, this question gets asked again and again) is something like "why do the lambdas I define in a loop all return the same result when the input value was different when each one was defined?" The same applies to regular functions, but people almo

[issue13094] Need Programming FAQ entry for the behavior of closures

2013-01-02 Thread Ezio Melotti
Ezio Melotti added the comment: I'm having some problem at deciding what the title of the FAQ should be, and what the actual problem is. ISTM that OP's problem is the same as: >>> x = 1 >>> def foo(): return x ... >>> x = 2 >>> foo() 2 except that he has 3 lambdas in a loop that get attached

[issue13094] Need Programming FAQ entry for the behavior of closures

2012-11-28 Thread Ezio Melotti
Changes by Ezio Melotti : -- assignee: docs@python -> ezio.melotti ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscrib

[issue13094] Need Programming FAQ entry for the behavior of closures

2012-11-18 Thread Ezio Melotti
Changes by Ezio Melotti : -- keywords: +easy stage: -> needs patch type: -> enhancement versions: +Python 3.4 ___ Python tracker ___ ___

[issue13094] Need Programming FAQ entry for the behavior of closures

2011-10-09 Thread Éric Araujo
Changes by Éric Araujo : -- assignee: -> docs@python components: +Documentation -None nosy: +eric.araujo versions: +Python 3.2, Python 3.3 ___ Python tracker ___ ___

[issue13094] Need Programming FAQ entry for the behavior of closures

2011-10-03 Thread Ezio Melotti
Ezio Melotti added the comment: Maybe with a different name is less confusing: lambda return_value=each: return_value This copies the value of 'each' in a variable called 'return_value' that is local to the lambda. Since the copy happens when the lambdas are defined, 'return_value' has then

[issue13094] Need Programming FAQ entry for the behavior of closures

2011-10-03 Thread Tomáš Dvořák
Tomáš Dvořák added the comment: Thank you all very much for the super-quick responses. I'm used to smalltalk, so the python variable binding behaviour is unnatural to me, but I guess there must have been some reasons for making it behave this way. Ezio, the "lambda each=each: each" trick w

[issue13094] Need Programming FAQ entry for the behavior of closures

2011-10-03 Thread Ezio Melotti
Ezio Melotti added the comment: To understand better what's going on, try to change the value of 'each' after the 3 prints and then call again the 3 methods: you will see that they now return the new value of each. This is because the lambdas refer to global 'each' (that at the end of the lo

[issue13094] Need Programming FAQ entry for the behavior of closures

2011-10-03 Thread R. David Murray
Changes by R. David Murray : -- title: setattr misbehaves when used with lambdas inside for loop -> Need Programming FAQ entry for the behavior of closures ___ Python tracker __