I'm putting together a Raku presentation for my co-workers and have a
section on state variables.  This is my example:

sub how-many {
    state $times;
    say "You called me {++$times} times";
}

> how-many
You called me 1 times
> how-many
You called me 2 times
> how-many
You called me 3 times

Then I thought I'd mention anonymous state variables by modifying my
example thusly:

sub how-many {
    say "You called me {++$} times";
}

But this gives:

> how-many
You called me 1 times
> how-many
You called me 1 times
> how-many
You called me 1 times

Is this the intended behavior?  The doc page on quoting constructs just
says that values can be interpolated with braces, but (at least to my eyes)
doesn't suggest that this involves creating a new scope, or a new function,
or however it is that this happens.

For my presentation I can just alter some lines to:

    say "You called me ", ++$times, " times";

and

    say "You called me ", ++$, " times";

...but that seems a bit less elegant than what I had originally.

Reply via email to