&get_and_inc_foo is a closure, because it binds a lexical variable defined outside of it.
If my example is a closure, then aren't all subroutines closures over the file-scoped lexicals in the file they're defined in?
If they don't use any lexicals defined outside them, they're not closures. sub foo { 1 } isn't a closure no matter where it's defined.
What I mean with making the subroutine a lexical anonymous subroutine is the following.my $foo; sub closure { $foo } sub not_closure { 1 }
my $foo; # lexical $foo = sub { $foo->() }; # closure local $bar; # dynamical $bar = sub { $bar->() }; # not a closure
ihb
Read argumentation in its context!
In reply to Re^6: Is it possible to create a sub exclusive to a sub? (nasty memory leak)
by ihb
in thread Is it possible to create a sub exclusive to a sub?
by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |