Re: problem with lambda / closures

2009-12-01 Thread Terry Reedy
Jussi Piitulainen wrote: Terry Reedy writes: definitions. Lambda expressions create functions just like def statements and are not closures and do not create closure unless nested within another function definition. Thinking otherwise is Seems quite closed in the top level environment to me:

Re: problem with lambda / closures

2009-12-01 Thread Jussi Piitulainen
Terry Reedy writes: > definitions. Lambda expressions create functions just like def > statements and are not closures and do not create closure unless > nested within another function definition. Thinking otherwise is Seems quite closed in the top level environment to me: Python 2.3.4 (#1, J

Re: problem with lambda / closures

2009-11-30 Thread Terry Reedy
Benjamin Kaplan wrote: I don't know if anyone considers python's incomplete implementation of closures a "feature" but it's documented so it's not really a bug either. I believe Python's implementation of closures is quite complete in 3.x. In what way do you consider it otherwise? One just ha

Re: problem with lambda / closures

2009-11-30 Thread Jussi Piitulainen
Benjamin Kaplan writes: > On Monday, November 30, 2009, Louis Steinberg wrote: > > I have run into what seems to be a major bug, but given my short > > exposure to Python is probably just a feature: > > > > running > > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) > > [GCC 4.0.1 (Apple Inc. bui

Re: problem with lambda / closures

2009-11-30 Thread inhahe
On Mon, Nov 30, 2009 at 10:54 AM, Benjamin Kaplan wrote: > > I don't know if anyone considers python's incomplete implementation of > closures a "feature" but it's documented so it's not really a bug > either. I believe there is a trick with default arguments to get this > to work, but I don't use

Re: problem with lambda / closures

2009-11-30 Thread Benjamin Kaplan
On Monday, November 30, 2009, Louis Steinberg wrote: > I have run into what seems to be a major bug, but given my short exposure to > Python is probably just a feature: > > running > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > with file fo

Re: problem with lambda / closures

2009-11-30 Thread Louis Steinberg
I figured out the answer to my own query. In the original example (see below), there was only one binding for k, which was shared by all the closures, so they all saw the same value. Consider: def fie2(k): return lambda: fie3(k) def fie3(m): print m def fie1(j): return fie2(j

Re: problem with lambda / closures

2009-11-30 Thread Duncan Booth
Louis Steinberg wrote: >== clip here > def p(d): > print d > > > l=[ ] > for k in [1,2,3]: > l.append(lambda : p(k)) > > for f in l: > f() > >== clip here > I get output > 3 > 3 > 3 > instead of >

Re: problem with lambda / closures

2009-11-30 Thread Marco Mariani
Louis Steinberg wrote: I have run into what seems to be a major bug, but given my short exposure to Python is probably just a feature: Yes, it works as advertised :-/ which I would expect. Can anyone explain this or give me a workaround? like this? def p(d): print d l=[ ] for