My first clue that something is amiss is in your third line of code when
the  return skips "AA" and starts "AB, AC, AD....". That suggests to me
that the two step assign/printf call is playing havoc with the $ anonymous
variable. Try this instead:

~$ raku -e 'for <AA NN> -> $alpha {  for (1..14) { printf("d: %s\n", (state
$ = $alpha)++ ) }; };'
d: AA
d: AB
d: AC
d: AD
d: AE
d: AF
d: AG
d: AH
d: AI
d: AJ
d: AK
d: AL
d: AM
d: AN
d: NN
d: NO
d: NP
d: NQ
d: NR
d: NS
d: NT
d: NU
d: NV
d: NW
d: NX
d: NY
d: NZ
d: OA

HTH, Bill.

On Tue, Sep 1, 2020 at 2:57 PM Andy Bach <andy_b...@wiwb.uscourts.gov>
wrote:

> I'm barely hanging on with the "$" so ... so from:
> raku -e 'for <AA NN> -> $alpha { for (1..14) {   print (state $ =
> $alpha)++ ~ " "  } }'
> AA AB AC AD AE AF
>
> I tried an actual, er, non-anon var
> # raku -e 'for <AA NN> -> $alpha { for (1..14) {   print (state $sv =
> $alpha)++ ~ " "  } }'
> AA AB AC AD AE AF ...
>
> and then I tried
> raku -e 'for <AA NN> -> $alpha {  for (1..14) { (state $sv = $alpha)++;
>  printf("d: %s\n", $sv ) } }'
> d: AB
> d: AC
> d: AD
> d: AE
> d: AF
> ...
>
> but back to "$"
>  raku -e 'for <AA NN> -> $alpha {  for (1..14) { (state $ = $alpha)++;
>  printf("d: %s\n", $ ) } }'
> Use of uninitialized value of type Any in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1
> Use of uninitialized value of type Any in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to
> something meaningful.
>   in any join at gen/moar/stage2/NQPCORE.setting line 1075
> d:
>
> [27 more times]
>
> I used printf hoping the %s context would stringify "$" as trying any of
> the suggested "methods" complain of a missing "self"
>  raku -e 'for <AA NN> -> $alpha {  for (1..14) { (state $ = $alpha)++;
>  printf("d: %s\n", $.raku ) } }'
> ===SORRY!=== Error while compiling -e
> Variable $.raku used where no 'self' is available
> at -e:1
> ------> v = $alpha)++;  printf("d: %s\n", $.raku⏏ ) } }
>     expecting any of:
>         term
>
> So I'm missing something about "$", I think
>
>
>
>
>
> ------------------------------
> *From:* William Michels via perl6-users <perl6-users@perl.org>
> *Sent:* Tuesday, September 1, 2020 3:17 PM
> *To:* yary <not....@gmail.com>
> *Cc:* perl6-users <perl6-users@perl.org>
> *Subject:* Re: print particular lines question
>
> I tried combining Larry's code and Yary's code, variously using
> "state" or "INIT" or "BEGIN". This is what I saw:
>
> ~$ raku -e 'for <AA NN> -> $alpha { for (1..14) { print (state $ =
> $alpha)++ ~ " " } }'
> AA AB AC AD AE AF AG AH AI AJ AK AL AM AN NN NO NP NQ NR NS NT NU NV
> NW NX NY NZ OA
>
> ~$ raku -e 'for <AA NN> -> $alpha { for (1..14) { print (INIT $ =
> $alpha)++ ~ " " } }'
> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
>
> ~$ raku -e 'for <AA NN> -> $alpha { for (1..14) { print (BEGIN $ =
> $alpha)++ ~ " " } }'
> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
>
> Expected?  --Bill.
>
> On Tue, Sep 1, 2020 at 11:44 AM yary <not....@gmail.com> wrote:
> >
> >
> > Thanks, that's cool, and shows me something I was wondering about
> >
> > On Tue, Sep 1, 2020 at 11:36 AM Larry Wall <la...@wall.org> wrote:
> >>
> >> If you want to re-initialize a state variable, it's probably better to
> make
> >> it explicit with the state declarator:
> >>
> >>     $ raku -e "for <a b> { for (1..2) { say (state $ = 'AAA')++ } }"
> >>     AAA
> >>     AAB
> >>     AAA
> >>     AAB
> >
> >
> > $ raku -e 'for <AA OO> -> $alpha { for (1..3) { say (state $ = $alpha)++
> } }'
> > AA
> > AB
> > AC
> > OO
> > OP
> > OQ
> >
>

Reply via email to