I'm trying to seek enlightenment regarding closures. I have read both the definition at wikipedia and also the definition in the Programming Perl book. Wikipedia's definition does not seem to require that the function be anonymous (like the Perl book does) - I think more to the point it does not say that the function needs to be created dynamically during run-time. The crux of the matter is, does it?
Is the following code snippet a closure?
The result is 4.{ my $i=1; sub addone { my $y=shift; $i++; return $i+$y; } } $i=10; print addone 2;
Certianly it satisfies being a funtion and having a special lexical environment. However the function and lexical environment are shared....
What say you monks?
In reply to Nailing down closures! by mattford63
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |