> -----Original Message-----
> 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;


We're really just pulling the block vars out so we can tweak them.

Perhaps the right approach is that all lexically scoped vars declared
"within" loop keywords that take blocks are parameters, and persist until
the end of the loop-block.

  while (my $line = <>) { # or loop, or for, or do/while, or whatever
   ...
  }

  print $line; # error -- line out of scope

The obvious accompaniment is C<is scoped(BLOCK)> or maybe C<is persistent>.

  FOR_LOOP:
  for (...) {
    while (my $line is scoped(FOR_LOOP) = <>) {
      ...
    }
    print $line; # Okay -- $line ends with the for.
  }

=Austin

Reply via email to