Buddha Buck writes: : At 07:57 AM 04-03-2002 -0800, Larry Wall wrote: : >Mark J. Reed writes: : >: loop (my $i=0; 1; $i++) { : >: </exegesis4> : > : >No, the scope of $i stays outside, per the previous decision. If you : >want it inside you can always make $i an official formal parameter: : > : > for 0 .. Inf -> $i { ... } : > : >I think that better documents a counted infinite loop in any case. : : Hmmm, in the more general case of: : : for (my $i = intializer(); condition($i); $i = advance($i)) { ... } : : where you might want $i to be lexically scoped in the for loop, is there a : way to do it?
Sure, just say { loop (my $i = intializer(); condition($i); $i = advance($i)) { ... } } : Perhaps something like: : : initalizer() -> $i { LOOP: NEXT { $i = advance($i); redo LOOP if : condition($i);} ... } : : except I'm not sure that that would have the same semantics. Other than that C<initializer> isn't going to be expecting a closure, and C<redo> would bypass the NEXT, and there's no loop there to C<redo>, and you'd have to make the parameter C<$i is rw>, why, it should work find. :-) : (Or, more generally, given a for loop with a "my", how sould perl52perl6 : deal with it? Probably just by slapping an extra set of curlies around it. Larry