On Thu, Jul 27, 2006 at 11:28:20AM +0900, Chad Perrin wrote:

> > Here's a better example:
> > 
> > def foo():
> >     x = [0]
> >     def bar():
> >         x[0] += 1
> >         print x[0]
> >     return bar
> > 
> > baz = foo()
> > baz()           -> 1
> > baz()           -> 2
> > baz()           -> 3
> 
> That's a bit clearer -- and it does look like a proper closure.  It also
> looks unnecessarily complex to implement.  Thanks for the example.

In practice, it's not really all that bad. Most of the places where I'd
end up using closures in, say Ruby and JavaScript, I'd end up using
generators, list comprehensions, &c. in Python. Having to name the inner
function's a bit of a pain, but generally I don't end up assigning to
the variables in the outer scope anyway, so that's not such a big deal
either.

Different stroke, and all that.

K.

-- 
Keith Gaughan - kmgaughan / eircom.net - http://talideon.com/
I hate babies.  They're so human.
		-- H. H. Munro