Re: When Closure get external variable's value?

2006-12-19 Thread Fredrik Lundh
Huayang Xia wrote: > I don't understand why while a nested function perfectly matches the > definition of closure, it is not closure simply because it is not used > by external world. Like so many other computing terms, the word "closure" is used in different ways by different people. Strictly

Re: When Closure get external variable's value?

2006-12-19 Thread Huayang Xia
My understanding was: Closure is a nested function first. If it refers free variable, then it is closure. If it doesn't refer free variable, it doesn't have to be nested. That is probably the reason, the free variable is emphasized. Normally it makes sense to return a closure, but not a non-closur

Re: When Closure get external variable's value?

2006-12-19 Thread Fredrik Lundh
Bruno Desthuilliers wrote: >> You skipped the first and most important sentence: > "In programming languages, a closure is a function that refers to free > variables in its lexical context." > > IOW, a closure is a function that carry it's own environment. in contrast to functions that don't k

Re: When Closure get external variable's value?

2006-12-19 Thread Bruno Desthuilliers
Huayang Xia a écrit : > I'm confused. What is the definition of closure. > > I'm not sure if it's correct, I get the definition from wikipedia: > > "A closure typically comes about when one function is declared entirely > within the body of another, and the inner function refers to local > variab

Re: When Closure get external variable's value?

2006-12-19 Thread Huayang Xia
I'm confused. What is the definition of closure. I'm not sure if it's correct, I get the definition from wikipedia: "A closure typically comes about when one function is declared entirely within the body of another, and the inner function refers to local variables of the outer function. At runtim

Re: When Closure get external variable's value?

2006-12-19 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Huayang Xia wrote: > That is a really concise and precise answer. Thanks. > > So the object binding can only happen explicitly at the closure > declaration argument list(non-free variable). That's no declaration that's a definition and it happens at runtime! It's execute

Re: When Closure get external variable's value?

2006-12-19 Thread Huayang Xia
That is a really concise and precise answer. Thanks. So the object binding can only happen explicitly at the closure declaration argument list(non-free variable). On Dec 19, 10:37 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Huayang Xia wrote: > > When does the closure get the value of the maxI

Re: When Closure get external variable's value?

2006-12-19 Thread Fredrik Lundh
Huayang Xia wrote: > When does the closure get the value of the maxIndex in the following > code snippet? > > def testClosure(maxIndex) : > > def closureTest(): > return maxIndex > > maxIndex += 5 > > return closureTest() > >

Re: When Closure get external variable's value?

2006-12-19 Thread Huayang Xia
Thanks for the clarification. But my question is: When does the closure get the value of the maxIndex in the following code snippet? def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest

Re: When Closure get external variable's value?

2006-12-18 Thread Jussi Salmela
Huayang Xia kirjoitti: > It will print 15. The closure gets the value at run time. > > Could we treat closure as part of the external function and it shares > the local variable with its holder function? > I don't quite get what you are trying to tell us but if you think that in your example co

Re: When Closure get external variable's value?

2006-12-18 Thread Huayang Xia
It will print 15. The closure gets the value at run time. Could we treat closure as part of the external function and it shares the local variable with its holder function? -- http://mail.python.org/mailman/listinfo/python-list

When Closure get external variable's value?

2006-12-18 Thread Huayang Xia
What will the following piece of code print? (10 or 15) def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest() print testClosure(10) My question is when the closure function gets val