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

Re: How much do we close over?

Thread Previous
From:
Piers Cawley
Date:
June 13, 2005 00:26
Subject:
Re: How much do we close over?
Message ID:
m27jgyhg4t.fsf@obelisk.bofh.org.uk
Rob Kinyon <rob.kinyon@gmail.com> writes:

>> Piers Cawley said:
>> 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.
>
> I'm not arguing with the idea, in general. I just want to point out
> that this implies that you're going to hold onto every single
> file-scoped lexical, leading to quite a bit of action-at-a-distance.

Well, duh. If eval string isn't a hearty pointer to the "This subroutine
deliberately takes advantage of action at a distance" then I don't know what
is.


> Maybe, instead, you should say "sub is lexical_stack(N)" where N is
> the number of scoping levels it will hold onto in addition to any
> lexical it actually refers to. I would have 0 be the innermost scope,
> 1 be the enclosing scope, etc.

Which is all very well, but you don't necessarily know how deep in the stack
you are. I want to be able to write something in such a way that evalling the
string works in exactly the same way as it would if I had just written a do
block in the first place.

    sub foo { my $x; ...; return sub { do {...} } }

It's an introspection thing. Most of the time you don't want it, but sometimes
you do and we really shouldn't be making that impossible.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About