On Saturday 22 March 2003 03:28 pm, Martin Weber wrote: > 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 ? I guess it is really a matter of semantics and whose definition you use. The reason I made my comment is that, in your fragment, x does not have a definition at all (at least not one that is shown) in the calling environment. In any event that is just scoping. To be a true closure, x would have to be a global. Now, x may be a global in your example, but there is nothing to indicate whether or not it is. > > -Martin > > PS: In about every scheme book I've seen, the classic closure example > is > > (define (mk-add x) > (lambda (n) > (+ x n))) -- Seth Kurtzberg M. I. S. Corp. 480-661-1849 seth / cql.com