in reply to Re^3: Syntax question about closures and Perl 'sort'
in thread Syntax question about closures and Perl 'sort'

Actually that is not quite right. If a variable is not visibly used in a returned subroutine, Perl cleans it up. You can verify that with this example:
sub create_closure { my $x = "x"; my $y = "y"; return sub { $y .= "y"; eval q{print "x: $x\ny: $y\n"}; }; } create_closure()->();
And you will find that $x is not properly remembered, but $y is.

Replies are listed 'Best First'.
Re^5: Syntax question about closures and Perl 'sort'
by jethro (Monsignor) on Apr 05, 2009 at 18:43 UTC

    Interesting fact of the disturbing kind ;-)

    The language designer or a programmer in that language would still call it a closure. That the implementation optimized it away would (normally) only interest the implementor of the language. That it can be revealed through an eval I would call an implementation bug. Ideally any optimization must not change the result of a programm execution.