On Sun, Mar 23, 2003 at 07:11:36AM +0900, Seth Kurtzberg wrote:
> On Saturday 22 March 2003 02:09 pm, Johann Hibschman wrote:
> > Seth Kurtzberg <seth / cql.com> writes:
> > > Ruby has closures, Python does not.  Not getting into the "who's better"
> > > argument; just citing a fact.
> >
> > Actually, no, that's wrong.  Python has had closures for a while now.
> >
> > >>> def make_adder(x):
> >
> > ....   def adder(y):
> > ....     return x + y
> > ....   return adder
> > ....
> >
> > >>> a10 = make_adder(10)
> > >>> a10(2)
> 
> I'll have to check whether python has changed, but this example is not a 
> closure.

Mind elaborating why it isn't ? In the definition of adder the value of
x is free, and determined by the lexical environment; make_adder defines
it. If it wasn't a closure, a10 would depend on the value of x in the
calling environment. It obviously doesn't. If it isn't a closure, what
else would you call it ?

-Martin

PS: In about every scheme book I've seen, the classic closure example
is 

(define (mk-add x)
	(lambda (n)
		(+ x n)))