Martin Weber <Ephaeton / gmx.net> writes:

> On Sun, Mar 23, 2003 at 07:52:46AM +0900, Joel VanderWerf wrote:
> > (...)
> > But in Python, the inner function only has access to the _object_, not 
> > to the original variable which refers to the object, and so you have to 
> > "box" the value inside an object if you want to have shared references. 
> > (.. ugliness ..)
> > I think this is what is meant when people say Python does not have closures.
> 
> Yikes. thanks for the clarification... been on the road so much with
> lisp/scheme/ruby that I implied if you have access to the value, you'd
> _of course_ have access to the binding, too :)

This seems like a strange distinction to make.  If you demand writable
access to bindings to have a closure, then none of the
side-effect-free functional languages like Haskell have closures, and
that just seems wrong.

Python's somewhere in-between the pure-functional and something like
lisp.  You can have access to modifiable objects, but you can't change
the binding to point to something else entirely.

A closure, IIRC, just means the function is closed over the local
bindings.  It keeps a reference to the local binding frame, so it's
"closed".  Python certainly does that.  The details of how you access
those bindings for changes seems to be a very minor point.

As a user of both python and ruby, it seems more fair to me to say
that "Ruby has more powerful closures than python" or "Ruby has more
convenient closures than python", not that "Python doesn't have
closures."

In any case, there doesn't seem to be much cause to argue over this,
but you might as well be as forthright in advocacy as you can be.

Cheers,

--Johann