develooper Front page | perl.perl6.language | Postings from June 2005

How much do we close over?

Thread Next
Piers Cawley
June 12, 2005 15:26
How much do we close over?
Message ID:
Chip and I have been having a discussion. I want to write:

    sub foo { my $x = 1; return sub { eval $^codestring } }
    say foo()("$x");

I claim that that should print 1. Chip claims it should throw a warning about
because of timely destruction. My claim is that a closure should close over the
entire lexical stack, and not simply those things it uses statically. Chip
claims the opposite, arguing that timely destruction implies that this is
absolutely the right thing to do. It's also quicker.

But dammit, I'm doing runtime evaluation of code strings, I don't care about

If it's not the default can it please be mandated that there be some way of

    sub foo { my $x = 1; return sub is lexically_greedy {eval $^codestring} }

in other words, some way of declaring that a subroutine wants to hang onto
every lexical it can see in its lexical stack, not matter what static analysis
may say.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About