On Sat, Jul 12, 2008 at 11:05:35AM -0500, Patrick R. Michaud wrote: > On Sat, Jul 12, 2008 at 08:50:44AM -0700, chromatic wrote: > > On Saturday 12 July 2008 08:06:33 Patrick R. Michaud wrote: > > > Short answer: cloning is what will enable the following to work: > > > > > > for 1..10 -> $x { > > > sub foo() { say $x; } > > > push(@foos, &foo); > > > } > > > > Is that really valid Perl 6 code? I can see "my sub foo" > > working there, but rebinding lexicals for global symbols goes > > against a decade of Perl 5 for me. > > I don't know if it's valid or not.
However, I think it'd be basically equivalent to the following non-loop (but recursive) version: sub bar($x) { sub foo() { say $x; } push(@foos, &foo); if $x < 10 { bar($x + 1); } } bar(1); Perhaps it doesn't make any sense, but I'd be hard-pressed to immediately say that this second version isn't valid. And I might be able to make the argument that it's nearly equivalent to for 1..10 -> $x { our &foo = -> { say $x; } push(@foos, &foo); } with the exception that &foo is uninitialized prior to the loop in this last version. Comments and counter-arguments welcome. Pm