Alexey Trofimenko writes:
> AFAIR, I've seen in some Apocalypse that lexical scope boundaries will be  
> the same as  boundaries of block, in which lexical variable was defined.

Yep.  Except in the case of routine parameters, but that's nothing new.

> 
> so, my question is, what the scope of variables, defined in C<if> and  
> C<loop> conditions?
> 
> in perl5:
> 
>   my $a="first\n";
>   if (my $a="second\n") {print $a}
>   print $a;
> 
> prints
> 
>   second
>   first
> 
> if I got it right, in perl6 same program will print
> 
>   second
>   second

Precisely.

> [...]

> so,
> 
>   loop (my $i=1;$i<10;$i++) { ... }
> 
> will declare $i for the rest of the block, in which loop is placed, won't  
> it?

Yep.

> I feel that I will write things like:
> 
>   {loop (my $i=1;$i<10;$i++) {
>       ...
>   }}

No you won't, for a couple reasons.

First, you'd instead be writing:

    for 1..9 -> $i {
        ...
    }

It's quite surprising how very many cases where you'd need loop can be
done with the new for.  Since $i is a sub parameter, it's only scoped to
the block of the loop.

But anyway, if you still want to be old school about it, then you'll end
up not caring about the scope of your $i.  Really you won't.  And you'll
be happy that it was kept around for you once you decide you want to
know the value of $i for which the loop terminated.

Luke

> But I really hope that I missed something important, stating that theese  
> curlies are not necessary.

Reply via email to