Talk:Closure (computer programming): Difference between revisions

Content deleted Content added
Line 753:
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)