cperl icon indicating copy to clipboard operation
cperl copied to clipboard

Make nested function definitions lexical by default

Open rurban opened this issue 7 years ago • 0 comments

sub makeAddr($x) {
    sub adder($y) {
        return $x + $y
    }
    \&adder
}

as if declared as my sub adder, adder is not added to the global namespace. But if the function is declared within eval string it is global, even when in another function block. You can also declare it as our sub adder to extend the scope to the current package, to be found with the method dispatch. The CV itself is stored in the lexical pad of makeAddr though still.

See also http://www.erights.org/elib/capability/ode/ode-objects.html

rurban avatar Oct 26 '18 08:10 rurban