Created
November 30, 2011 02:05
-
-
Save hpcx82/1407652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub make_adder | |
{ | |
my $addpiece = shift; | |
return sub { shift + $addpiece }; | |
} | |
$f1 = make_adder(20); | |
&f1(1); # = 21; | |
&f1(2); # = 22; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
closure - use a local variable in another function, then you can use that function elsewhere, even it is not in the context of that local variable. (the local variable is either cloned, or ref-counted)