develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #119049] referencing some variables hides others from PadWalkerstarting 5.17.2

Thread Previous | Thread Next
From:
Steffen Mueller
Date:
August 2, 2013 05:24
Subject:
Re: [perl #119049] referencing some variables hides others from PadWalkerstarting 5.17.2
Message ID:
51FB426B.9070404@cpan.org
On 08/01/2013 01:35 AM, Ricardo SIGNES via RT wrote:
> On Tue Jul 30 16:05:09 2013, sprout wrote:
>> In short: closures close over variables, not lexical scopes, unless
>> string eval is involved.  (So one can work around this by including eval
>> "" in the sub.)
>
> When did this become true in practice?

I think it has "always" been like that.

> It does not match up with what I take to be common definition of closures as enclosing a
> complete environment.  I agree that PadWalker is letting Perl programmers go beyond the realm
> of polite behavior, but let's put that aside.

This is quite interesting as I've always knownsumed[1] that it's 
variables being closed over, not full environments, for the reasons Dave 
described. And that is as a Perl user. It's only very recently with PLua 
that I've looked into how closures work and tried to meddle with them.

> Why shouldn't this program be able to print 2?

Because closing over variables (which it has always been, I believe) 
happens at run-time apart from the eval "" exception.

> What are the practical wins to making closure per-variable instead of per-environment?

This was already answered, I believe.

--Steffen

[1] Sounds better than assknown, dunnit?

Thread Previous | Thread Next


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