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

[perl #119049] referencing some variables hides others from PadWalker starting 5.17.2

Thread Previous | Thread Next
From:
Ricardo SIGNES via RT
Date:
July 31, 2013 23:35
Subject:
[perl #119049] referencing some variables hides others from PadWalker starting 5.17.2
Message ID:
rt-3.6.HEAD-2552-1375313713-493.119049-15-0@perl.org
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?

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.

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

  use 5.12.0;
  use PadWalker 'peek_my';

  my $x = 1;

  use Data::Dumper;

  my $z = sub { 
    warn Dumper(peek_my(1)); 
    eval { ${ peek_my(1)->{'$x'} } = 2 } 
  };

  my $w = sub { $z->() };

  $w->();

  say $x;

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

-- 
rjbs

---
via perlbug:  queue: perl5 status: rejected
https://rt.perl.org:443/rt3/Ticket/Display.html?id=119049

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