Re: Confused about closures and scoping rules

2007-11-07 Thread Jakub Hegenbart
On Wed, 07 Nov 2007 01:37:00 +0100, Chris Mellon <[EMAIL PROTECTED]> wrote: > Are there languages where closures *don't* behave like this? A closure > that used a copy of the state rather than the actual state itself > doesn't seem as useful. For references sake, JavaScript (the only > language th

Re: Confused about closures and scoping rules

2007-11-07 Thread Rhamphoryncus
On Nov 6, 5:37 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On Nov 6, 2007 6:23 PM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > > > On Tue, 06 Nov 2007 17:07:47 -0700, Fernando Perez <[EMAIL PROTECTED]> > > wrote: > > > [snip] > > > >This struck me as counterintuitive, but I couldn't find

Re: Confused about closures and scoping rules

2007-11-07 Thread Bruno Desthuilliers
Michele Simionato a écrit : > On Nov 6, 7:37 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: >> On Nov 6, 2007 6:23 PM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: >>> Lots of people ask about this. The behavior you observed is the expected >>> (by the implementors, anyway) behavior. >> Are there

Re: Confused about closures and scoping rules

2007-11-06 Thread Michele Simionato
On Nov 6, 7:37 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On Nov 6, 2007 6:23 PM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > > Lots of people ask about this. The behavior you observed is the expected > > (by the implementors, anyway) behavior. > > Are there languages where closures *don

Re: Confused about closures and scoping rules

2007-11-06 Thread Fernando Perez
Diez B. Roggisch wrote: > It's a FAQ. The reason is that the created closures don't capture the > _value_, but the _name_. Plus of course the locals()-dictionary outside > the function a to perform the lookup of that name. Which has the value > bound to it in the last iteration. > > Common cure

Re: Confused about closures and scoping rules

2007-11-06 Thread Chris Mellon
On Nov 6, 2007 6:23 PM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On Tue, 06 Nov 2007 17:07:47 -0700, Fernando Perez <[EMAIL PROTECTED]> wrote: > > [snip] > > > >This struck me as counterintuitive, but I couldn't find anything in the > >official docs indicating what the expected behavior sho

Re: Confused about closures and scoping rules

2007-11-06 Thread Diez B. Roggisch
Fernando Perez schrieb: > Hi all, > > consider the following small example: > > """ > Small test to try to understand a strange subtlety with closures > """ > > def outer(nmax): > > aa = [] > for n in range(nmax): > > def a(y): > return (y,n) > print 'Closur

Re: Confused about closures and scoping rules

2007-11-06 Thread Jean-Paul Calderone
On Tue, 06 Nov 2007 17:07:47 -0700, Fernando Perez <[EMAIL PROTECTED]> wrote: > [snip] > >This struck me as counterintuitive, but I couldn't find anything in the >official docs indicating what the expected behavior should be. Any >feedback/enlightenment would be welcome. This problem appeared deep

Confused about closures and scoping rules

2007-11-06 Thread Fernando Perez
Hi all, consider the following small example: """ Small test to try to understand a strange subtlety with closures """ def outer(nmax): aa = [] for n in range(nmax): def a(y): return (y,n) print 'Closure and cell id:',id(a.func_closure),\ id(a.