I stumbled across this issue while descending into a recursive Match
structure. Consider the following reentrant subroutine:
sub f($n) {
for 0..$n -> $i {
say "$i of 0..$n";
if ($i == 4) {
f(0);
}
}
};
f(6);
The value of the argument, $n, gets overwritten on reentry.
0 of 0..6
1 of 0..6
2 of 0..6
3 of 0..6
4 of 0..6
0 of 0..0
5 of 0..0
6 of 0..0
The last two lines of output should say "0..6" not "0..0".
Am I supposed to making the sub argument lexical?
sub f(my $n) { ... }
But Rakudo doesn't like that syntax.
Chris