On Tue, Nov 22, 2005 at 09:32:37AM -0800, Chip Salzenberg wrote: > On Tue, Nov 22, 2005 at 03:28:02PM +0100, Leopold Toetsch wrote: > > sub do_add3 { > > my $a = $_[0]; > > sub add3 { > > $a + 3; > > } > > add3(); > > } > > What Perl 5 does with that case is just a plain old bug, or more > precisely, a consequence of how Perl 5 implements capturing a lexical > environment. It's just bad. Don't even try supporting it.
As the current "owner" of the perl5 closure code, (and as someone who hasn't been following this thread :-( ), I'm interested to know what the p6 semantics of this are. The p5 semantics seem to me to be logical and consistent, if not particularly useful in this case: ie subs capture their outside lexical scope at the time they are created. So at compile time, add3() captures the first instance of do_add3()'s $a and hangs onto it for dear life. In p6, will $a remain shared between the two subs? In which case, at what point is $a considered to have gone out of, or come into scope, from the perspective of creating and destroying instances of lexicals variables? Dave -- Monto Blanco... scorchio!