use v6;
use Test;
plan 9;
my @list = ('a');
for @list -> $letter { is( $letter , 'a', 'can bind to variable in pointy') }
{
for @list -> {
isnt($_, 'a', '$_ does not get set implicitly if a pointy is given')
}
}
for @list -> $letter {
isnt( $_ ,'a', '$_ does not get set implicitly if a pointy is given')
}
{
my $a := $_; $_ = 30;
for 1 .. 3 { $a++ };
is $a, 33, 'outer $_ increments' ;
}
{
my @mutable_array = 1..3;
lives_ok { for @mutable_array { $_++ } }, 'default topic is rw by default';
}
{
$_ = 1;
my $tracker = '';
for 11,12 -> $a {
if $_ == 1 { $tracker ~= "1 : $_|"; $_ = 2; }
else { $tracker ~= "* : $_" }
}
is $tracker, '1 : 1|* : 2',
'Two iterations of a loop share the same $_ if it is not a formal parameter';
}
{
$_ = 1;
sub foo {
ok !defined($_), '$_ starts undefined';
$_ = 2;
is $_, 2, 'now $_ is 2';
}
foo();
is $_, 1, 'outer $_ is unchanged'
}