> -----Original Message-----
> From: Luke Palmer [mailto:[EMAIL PROTECTED]
> Austin Hastings writes:
> > > From: Luke Palmer [mailto:[EMAIL PROTECTED]
> >
> > > Actually, in Perl 6, they'll do that anyway. Scope in loops is
> > > strictly defined by the location of the braces WRT the location of
> > > "my". That is:
> > >
> > > while (my $x = somefunc()) { ... }
> > > # $x still in scope
> > >
> > > And the same for all other loops. C<for> loops are an "exception",
> > > sortof, because they're really declaring a parameterized block instead
> > > of a lexical variable.
> >
> > It seems like we could maybe generalize this "exception":
> >
> > In cases where we say
> >
> > my &block = -> $a, $b { do_stuff; }
> >
> > for (my $a = 0, $b = 1; $a < $b; ++$a) block;
>
> Uh, can't do that. Plus, you mean to say:
>
> loop (my ($a, $b) = (0, 1); $a < $b; ++$a), █
>
> C<for> is called C<loop>, and the & is required to avoid using the return
> value of calling C<block>. The , is required because it's not a curly
> block, and commas are only optional when it is.
>
> And you can't do that because the loop has no way of knowing that your
> lexicals are referring to &block's parameters.
Which begs the question:
my &blk = -> $a, $b {...};
for (@list) &blk;
What happens?
(IOW, how do we map locals/parameters into block vars?)
Or, given
my &blk = -> $a {...};
loop (my ($x, $max) = (0, -1);
$x < $num_elts;
$x++, $max = max($max, $x)),
&blk;
What happens?
(IOW, in a "target-rich" environment, how do we know what to bind?)
> Then again, C<for>
> could be made to do that using named parameters, but I don't think it
> will (there are some nasty traps with variables in outer scopes). It's
> easy enough to say:
>
> loop (my ($a, $b) = (0, 1); $a < $b; ++$a) { block($a, $b) }
>
Or maybe we have to say
loop (...) -> $a &blk;
But that's nasty.
> Now on to your argument :-)
>
> > We're really just pulling the block vars out so we can tweak them.
>
> Yeah, sortof.
...
> It's a beginner trap, so Larry changed it to follow intuition. It can
> be useful in a couple places, and it never really gets in your way. So,
> poof, no more magic scopes.
Hooray for newbies. And that's a good point.
I'm still curious about the binding rules, though.
=Austin