Re: Curious corner cases concerning closure cloning

2006-08-14 Thread Jonathan Scott Duff
On Mon, Aug 14, 2006 at 04:01:47PM +, Luke Palmer wrote: > What do these do? > > for 1,2 { > my $code = { > my $x; > BEGIN { $x = 42 } > $x; > }; > say $code(); > } Assuming that variables are available immediately as they are parsed and that BEGIN

Re: Curious corner cases concerning closure cloning

2006-08-14 Thread Yuval Kogman
On Mon, Aug 14, 2006 at 16:01:47 +, Luke Palmer wrote: > What do these do? Intuition based answers: > for 1,2 { > my $code = { > my $x; > BEGIN { $x = 42 } > $x; > }; > say $code(); > } I think the closure would be emitted equivalently to my $x = 4

Curious corner cases concerning closure cloning

2006-08-14 Thread Luke Palmer
What do these do? for 1,2 { my $code = { my $x; BEGIN { $x = 42 } $x; }; say $code(); } for 1,2 { my $code = { state $x; BEGIN { $x = 42 } # mind you, not FIRST $x++; }; say $code(); say $code(); } fo