Talk:Closure (computer programming): Difference between revisions

Content deleted Content added
Ruud Koot (talk | contribs)
m Clarity: gr.
Line 747:
 
:: I do think that the final part of the first sentence ("for the non-local variables of that function.") needs to be clarified. In particular it might be possible to give a definition of "referencing environment" instead. Something along the lines of "a map containing [[name binding|binding]]s for the [[non-local variable]]s of that function."?—''[[User:Ruud Koot|Ruud]]'' 21:47, 28 December 2011 (UTC)
 
== First Example (Python) ==
 
Please note that I have never written a line of code in python and have no idea how variables are initialized and values assigned.
But I am worried that the following snippet that is used as the first example in the article may have an error. Can someone please help me understand where the value for 'y' is initialized in the incrementer() function? I understand that the lambda function would have access to 'x', which is defined within it's parent function. But, in the first call to (initialization of) incrementer, the value of y=undefined, but the snippet seems to indicate that it is initialized to 0(int).
 
def incrementer(x=1):
return lambda y: x+y
incr1 = incrementer(1)
print incr1(2) # 3
incr2 = incrementer(2)
print incr2(3) # 5
 
[[Special:Contributions/166.248.77.56|166.248.77.56]] ([[User talk:166.248.77.56|talk]]) 03:26, 11 February 2012 (UTC)