Re: Weird lambda behavior (bad for)

2009-04-26 Thread Aahz
In article , namekuseijin wrote: > >I don't like *for* at all. It both makes it tough to get true closures >and also unnecessarily pollutes the namespace with non-local variables. Maybe. Consider this standard Python idiom: for x in L: if x == criterion: break doSomething(x) Obv

Re: Weird lambda behavior (bad for)

2009-04-25 Thread namekuseijin
The real issue here has nothing to do with closures, lexical capture or anything like that. It's a long known issue called side-effects. Trying to program in a functional style in the presence of side-effects is bad. *for* is the main perpetrator of side-effects here, because it updates its

Re: Weird lambda behavior

2009-04-22 Thread Chris Rebert
On Wed, Apr 22, 2009 at 3:32 PM, Benjamin Peterson wrote: > Chris Rebert rebertia.com> writes: >> Common wart to run into as of late. fn (in the lambda) doesn't get >> evaluated until the call-time of the lambda, by which point the loop >> has finished and the loop variable has been changed to it

Re: Weird lambda behavior

2009-04-22 Thread Benjamin Peterson
Chris Rebert rebertia.com> writes: > Common wart to run into as of late. fn (in the lambda) doesn't get > evaluated until the call-time of the lambda, by which point the loop > has finished and the loop variable has been changed to its final > value, which is used by the lambda. How is that a war

Re: Weird lambda behavior

2009-04-22 Thread Scott David Daniels
Dave Angel wrote: ... Incidentally, in your example, I believe you needed the *y and **z in the actual parameters to __callFn__() Also, use a name like __callFn rhather than __callFn__ -- You are treading on Pythons internal names if you put __ at the beginning _and_ the end, and will con

Re: Weird lambda behavior

2009-04-22 Thread Diez B. Roggisch
Rüdiger Ranft wrote: > Hi all, > > I want to generate some methods in a class using setattr and lambda. > Within each generated function a name parameter to the function is > replaced by a string constant, to keep trail which function was called. > The problem I have is, that the substituted name

Re: Weird lambda behavior

2009-04-22 Thread Dave Angel
Rüdiger Ranft wrote: Hi all, I want to generate some methods in a class using setattr and lambda. Within each generated function a name parameter to the function is replaced by a string constant, to keep trail which function was called. The problem I have is, that the substituted name parameter

Re: Re: Weird lambda behavior

2009-04-22 Thread Rüdiger Ranft
Chris Rebert schrieb: > On Wed, Apr 22, 2009 at 4:50 AM, Rüdiger Ranft <_r...@web.de> wrote: >> Hi all, >> >> I want to generate some methods in a class using setattr and lambda. >> Within each generated function a name parameter to the function is >> replaced by a string constant, to keep trail wh

Re: Weird lambda behavior

2009-04-22 Thread Chris Rebert
On Wed, Apr 22, 2009 at 4:50 AM, Rüdiger Ranft <_r...@web.de> wrote: > Hi all, > > I want to generate some methods in a class using setattr and lambda. > Within each generated function a name parameter to the function is > replaced by a string constant, to keep trail which function was called. > Th