Confused about closures and scoping rules

Chris Mellon arkanes at gmail.com
Tue Nov 6 19:37:00 EST 2007


On Nov 6, 2007 6:23 PM, Jean-Paul Calderone <exarkun at divmod.com> wrote:
> On Tue, 06 Nov 2007 17:07:47 -0700, Fernando Perez <fperez.net at gmail.com> 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 inside a
> >complicated code and it took me almost two days to track down what was going
> >on...
>
> Lots of people ask about this.  The behavior you observed is the expected
> (by the implementors, anyway) behavior.
>

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 that a) has closures and b) I have a handy way to test with)
does the same thing.



More information about the Python-list mailing list