On Tue, Nov 22, 2005 at 03:28:02PM +0100, Leopold Toetsch wrote: > Below are two cases of inner subs in Perl5 and Python. The first > (do_add3) is a plain nested subroutine, which is in the call chain. The > second (mk_add3) uses a closure. perl5 can't deal with case 1 properly > and warns. > > The question is: should Parrot cover case 1 too with :outer and it's > default LexPad, or how would the code be translated to PIR? > > 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. OTOH, that same case in Perl 6 is a normal closure and is supported with the default LexPad: .sub do_add3 get_params "(0)", $P0 .lex '$a', $P0 .lex '&add3', $P1 .const .Sub add3 = "add3" $P1 = newclosure add3 $P1() .end .sub add3 :anon :outer(do_add3) $P0 = fetch_lex '$a' $P1 = $P0 + 3 .return ($P1) .end -- Chip Salzenberg <[EMAIL PROTECTED]>