On Nov 26, 2:28 pm, [EMAIL PROTECTED] wrote: > Alphones: > > > it is a little deferent from other script language. > > See also here:http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping > > Python doesn't have such automatic closures, probably for performance > reasons and/or maybe to keep its C implementation simpler (maybe other > people here can give you an explanation of this, I too am curious).
Python has closures which are just fine. The issue here is the for loop. In Python (as in Common Lisp) the for loop works by *mutating* a single loop index. The closures will get the latest value of the loop index. In Haskell or Scheme the natural way to define a for loop is by introducing a new index variable at each iteration: there is no mutation. Each closure get its own index, with the right value. It is a design choice: Guido and the Common Lisp implementors are happy with mutating the loop index. I myself prefer the functional way. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list