> Larry has said very clearly that in Perl 6 there are no "magical" lexical scopes.
> That is, variables declared in a C<loop> control aren't magically in the
> following block.

However, I don't agree with him. It may be more intuitive to newcomers, 
but it is a common programming idiom that is used a lot. The C++ 
programmer expects it to be scoped the traditional way; the Java 
programmer does too; not to mention all those old Perl 5 programmers.

If someone doesn't know Perl that well, but they know other languages, 
seeing:

loop (my $x = 0; $x < 100; $x++) {
        something();
}
$x--;

Would be confusing. I know _I_ would look for the latter $x's scope, and 
assume it was bad program design. But then I realize that there's no $x in 
the enclosing scope, and I realize that it works. But if I have to stop 
and think about it, it makes it harder to read, if you know what I mean.

And what about closures?

{
        my @subs;
        loop (my $x = 0; $x < 10; $x++) {
                push @subs, { $^a + $x };
        }
        $x--;
        # ...
}

This certainly does *not* DWIM in the current thought. And the silence  
would be much more confusing than a simple syntax error the traditional 
way with the same code; that is assuming use strict is enabled.


Oh, and while we're on the topic of loops, I think NEXT needs a renaming. 
Because this block is executed even on the last iteration, right? So I 
think it would be more intuitive to name it POST, or AFTEREACHITERATION 
:).

Luke

Reply via email to