Re: print particular lines question
> Every time $ shows up, it is a different scalar. Ah ... I was mistakenly thinking it was akin to $_ etc, where you could just use it for "free" but it persisted as any var would. So, in: raku -e 'for -> $alpha { for (1..14) { say (state $ = $alpha)++; } } it's the "state" that keeping it around, but only ... arrgh! I'm going to have to read https://docs.raku.org/language/variables#The_state_declarator a few more times ... $ normally doesn't need state, but if you want the assignment to happen just once (as above), you need to explicitly add the state. Without an assignment: raku -e 'for -> $alpha { for (1..14) { say $++; } }' # 0-13 0-13 raku -e 'for -> $alpha { for (1..14) { say state $++; } }' # 0-13 0-13 Those the same, but raku -e 'for -> $alpha { for (1..14) { say ( $ = $alpha)++; } } just shows AA and NN 14 times. Because the inner for loops block is being "rerun", the state-liness of $ works, but when the outer loop loops (from AA to NN) the inner block and the inner version of $ go away. raku -e 'for -> $alpha { for (1..14) { say (state $ = $alpha)++; say "d2: " ~ ++$ } }' AA d2: 1 AB d2: 2 ... By Geoffrey, I think I almost have it! Thanks! From: yary Sent: Tuesday, September 1, 2020 6:16 PM To: Andy Bach Cc: William Michels ; perl6-users Subject: Re: print particular lines question Every time $ shows up, it is a different scalar. $=1; say $; is similar to my $anonONE=1; say $anonTWO; thus they are very limited use -y On Tue, Sep 1, 2020 at 3:55 PM Andy Bach mailto:andy_b...@wiwb.uscourts.gov>> wrote: > 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 Missed that about the missing AA - does the same thing with a named var, though: raku -e 'for -> $alpha { for (1..14) { (state $sv = $alpha)++; printf("d: %s\n", $sv ) } }' d: AB d: AC So raku -e 'for -> $alpha { for (1..14) { say (state $sv = $alpha)++; printf("d: %s\n", $sv ) } }' AA d: AB AB d: AC Ah, the increment happens the initial assignment. $sv = "AA"; $sv++; print $sv; # AB but the say (state $sv = $alpha)++ says the result of the assignment, then the increment. My confusion was more about my inability to use "$" anywhere else. raku -e 'for -> $alpha { for (1..14) { say (state $ = $alpha)++; printf("d: %s\n", $ ) } }' AA 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: AB Use of uninitialized value of type Any in string context. ... break it out of the parens, and it loses some "stateness": raku -e 'for -> $alpha { for (1..14) { say state $ = $alpha; $++; printf("d: %s\n", $ ) } }' AA 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 ... AA but the named doesn't raku -e 'for -> $alpha { for (1..14) { state $sv = $alpha; say $sv; $sv++; printf("d: %s\n", $sv ) } }' AA d: AB AB d: AC From: William Michels mailto:w...@caa.columbia.edu>> Sent: Tuesday, September 1, 2020 5:30 PM To: Andy Bach mailto:andy_b...@wiwb.uscourts.gov>> Cc: yary mailto:not@gmail.com>>; perl6-users mailto:perl6-users@perl.org>> Subject: Re: print particular lines question 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 -> $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 mailto:andy_b...@wiwb.uscourts.gov>> wrote: I'm barely hanging on with the "$" so ... so from: raku -e 'for -> $alpha { for (1..14) { print (state $ = $alpha)++ ~ " " } }' AA AB AC AD AE AF I tried an actual, er, non-anon var # raku -e 'for -> $alpha { for (1..14) { print (state $sv = $alpha)++ ~ " " } }' AA AB AC AD AE AF ... and then I tried r
Re: print particular lines question
Every time $ shows up, it is a different scalar. $=1; say $; is similar to my $anonONE=1; say $anonTWO; thus they are very limited use -y On Tue, Sep 1, 2020 at 3:55 PM Andy Bach wrote: > > 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 > > Missed that about the missing AA - does the same thing with a named var, > though: > raku -e 'for -> $alpha { for (1..14) { (state $sv = $alpha)++; > printf("d: %s\n", $sv ) } }' > d: AB > d: AC > > So > raku -e 'for -> $alpha { for (1..14) { say (state $sv = > $alpha)++; printf("d: %s\n", $sv ) } }' > AA > d: AB > AB > d: AC > > Ah, the increment happens the initial assignment. > $sv = "AA"; > $sv++; > print $sv; # AB > > but the > say (state $sv = $alpha)++ > > says the result of the assignment, then the increment. My confusion was > more about my inability to use "$" anywhere else. > raku -e 'for -> $alpha { for (1..14) { say (state $ = $alpha)++; > printf("d: %s\n", $ ) } }' > AA > 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: > AB > Use of uninitialized value of type Any in string context. > ... > > break it out of the parens, and it loses some "stateness": > raku -e 'for -> $alpha { for (1..14) { say state $ = $alpha; > $++; printf("d: %s\n", $ ) } }' > AA > 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 > ... > AA > > but the named doesn't > raku -e 'for -> $alpha { for (1..14) { state $sv = $alpha; say > $sv; $sv++; printf("d: %s\n", $sv ) } }' > AA > d: AB > AB > d: AC > > > > > -- > *From:* William Michels > *Sent:* Tuesday, September 1, 2020 5:30 PM > *To:* Andy Bach > *Cc:* yary ; perl6-users > *Subject:* Re: print particular lines question > > 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 -> $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 > wrote: > > I'm barely hanging on with the "$" so ... so from: > raku -e 'for -> $alpha { for (1..14) { print (state $ = > $alpha)++ ~ " " } }' > AA AB AC AD AE AF > > I tried an actual, er, non-anon var > # raku -e 'for -> $alpha { for (1..14) { print (state $sv = > $alpha)++ ~ " " } }' > AA AB AC AD AE AF ... > > and then I tried > raku -e 'for -> $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 -> $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 -> $alpha { for (1..14) { (state $ = $alpha)++; > printf("d: %s\n", $.raku ) } }' > ===
Re: print particular lines question
> 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 Missed that about the missing AA - does the same thing with a named var, though: raku -e 'for -> $alpha { for (1..14) { (state $sv = $alpha)++; printf("d: %s\n", $sv ) } }' d: AB d: AC So raku -e 'for -> $alpha { for (1..14) { say (state $sv = $alpha)++; printf("d: %s\n", $sv ) } }' AA d: AB AB d: AC Ah, the increment happens the initial assignment. $sv = "AA"; $sv++; print $sv; # AB but the say (state $sv = $alpha)++ says the result of the assignment, then the increment. My confusion was more about my inability to use "$" anywhere else. raku -e 'for -> $alpha { for (1..14) { say (state $ = $alpha)++; printf("d: %s\n", $ ) } }' AA 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: AB Use of uninitialized value of type Any in string context. ... break it out of the parens, and it loses some "stateness": raku -e 'for -> $alpha { for (1..14) { say state $ = $alpha; $++; printf("d: %s\n", $ ) } }' AA 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 ... AA but the named doesn't raku -e 'for -> $alpha { for (1..14) { state $sv = $alpha; say $sv; $sv++; printf("d: %s\n", $sv ) } }' AA d: AB AB d: AC ____ From: William Michels Sent: Tuesday, September 1, 2020 5:30 PM To: Andy Bach Cc: yary ; perl6-users Subject: Re: print particular lines question 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 -> $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 mailto:andy_b...@wiwb.uscourts.gov>> wrote: I'm barely hanging on with the "$" so ... so from: raku -e 'for -> $alpha { for (1..14) { print (state $ = $alpha)++ ~ " " } }' AA AB AC AD AE AF I tried an actual, er, non-anon var # raku -e 'for -> $alpha { for (1..14) { print (state $sv = $alpha)++ ~ " " } }' AA AB AC AD AE AF ... and then I tried raku -e 'for -> $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 -> $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 -> $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 mailto:perl6-users@perl.org>> Sent: Tuesday, September 1, 2020 3:17 PM To: yary mailto:not@gmail.com>> Cc: perl6-users mailto: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 -> $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
Re: print particular lines question
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 -> $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 wrote: > I'm barely hanging on with the "$" so ... so from: > raku -e 'for -> $alpha { for (1..14) { print (state $ = > $alpha)++ ~ " " } }' > AA AB AC AD AE AF > > I tried an actual, er, non-anon var > # raku -e 'for -> $alpha { for (1..14) { print (state $sv = > $alpha)++ ~ " " } }' > AA AB AC AD AE AF ... > > and then I tried > raku -e 'for -> $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 -> $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 -> $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 > *Sent:* Tuesday, September 1, 2020 3:17 PM > *To:* yary > *Cc:* perl6-users > *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 -> $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 -> $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 -> $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 wrote: > > > > > > Thanks, that's cool, and shows me something I was wondering about > > > > On Tue, Sep 1, 2020 at 11:36 AM Larry Wall 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 { for (1..2) { say (state $ = 'AAA')++ } }" > >> AAA > >> AAB > >> AAA > >> AAB > > > > > > $ raku -e 'for -> $alpha { for (1..3) { say (state $ = $alpha)++ > } }' > > AA > > AB > > AC > > OO > > OP > > OQ > > >
Re: print particular lines question
I'm barely hanging on with the "$" so ... so from: raku -e 'for -> $alpha { for (1..14) { print (state $ = $alpha)++ ~ " " } }' AA AB AC AD AE AF I tried an actual, er, non-anon var # raku -e 'for -> $alpha { for (1..14) { print (state $sv = $alpha)++ ~ " " } }' AA AB AC AD AE AF ... and then I tried raku -e 'for -> $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 -> $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 -> $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 Sent: Tuesday, September 1, 2020 3:17 PM To: yary Cc: perl6-users 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 -> $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 -> $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 -> $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 wrote: > > > Thanks, that's cool, and shows me something I was wondering about > > On Tue, Sep 1, 2020 at 11:36 AM Larry Wall 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 { for (1..2) { say (state $ = 'AAA')++ } }" >> AAA >> AAB >> AAA >> AAB > > > $ raku -e 'for -> $alpha { for (1..3) { say (state $ = $alpha)++ } }' > AA > AB > AC > OO > OP > OQ >
Re: print particular lines question
Yes, because INIT and BEGIN happen before runtime, and $alpha is set at runtime! Hence my original BEGIN example using a constant to set the first value. Another reason to prefer "state" over those phasers... unless you want a counter over the lifetime of the process, which is valid. -y On Tue, Sep 1, 2020 at 1:17 PM William Michels wrote: > 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 -> $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 -> $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 -> $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 wrote: > > > > > > Thanks, that's cool, and shows me something I was wondering about > > > > On Tue, Sep 1, 2020 at 11:36 AM Larry Wall 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 { for (1..2) { say (state $ = 'AAA')++ } }" > >> AAA > >> AAB > >> AAA > >> AAB > > > > > > $ raku -e 'for -> $alpha { for (1..3) { say (state $ = $alpha)++ > } }' > > AA > > AB > > AC > > OO > > OP > > OQ > > >
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 -> $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 -> $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 -> $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 wrote: > > > Thanks, that's cool, and shows me something I was wondering about > > On Tue, Sep 1, 2020 at 11:36 AM Larry Wall 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 { for (1..2) { say (state $ = 'AAA')++ } }" >> AAA >> AAB >> AAA >> AAB > > > $ raku -e 'for -> $alpha { for (1..3) { say (state $ = $alpha)++ } }' > AA > AB > AC > OO > OP > OQ >
Re: print particular lines question
Thanks, that's cool, and shows me something I was wondering about On Tue, Sep 1, 2020 at 11:36 AM Larry Wall 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 { for (1..2) { say (state $ = 'AAA')++ } }" > AAA > AAB > AAA > AAB > $ raku -e 'for -> $alpha { for (1..3) { say (state $ = $alpha)++ } }' AA AB AC OO OP OQ
Re: print particular lines question
On Mon, Aug 31, 2020 at 05:05:53PM -0700, yary wrote: : I like this better for alpha counter : : raku -e "for (1..4) { say (BEGIN $ = 'AAA')++ }" : : with BEGIN, the assignment of AAA happens once. With the earlier ||= it : checks each time through the loop. : -y Careful with that, though, since BEGIN/INIT happen only once ever (and in the context of the top-level run), so the state variable acts more like a global: $ raku -e "for { for (1..2) { say (BEGIN $ = 'AAA')++ } }" AAA AAB AAC AAD $ raku -e "for { for (1..2) { say (INIT $ = 'AAA')++ } }" AAA AAB AAC AAD If you want to re-initialize a state variable, it's probably better to make it explicit with the state declarator: $ raku -e "for { for (1..2) { say (state $ = 'AAA')++ } }" AAA AAB AAA AAB Larry
Re: print particular lines question
Nope $_ is the "default topic" if you want to use the jargon. It has a name, the underscore character. $ is a nameless variable, jargon is "anonymous scalar" $_ is different specialness from $ -y On Mon, Aug 31, 2020 at 5:13 PM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > On 2020-08-31 17:03, yary wrote: > > anonymous variable > > Would be safe thinking it had the same properties as `$_`? >
Re: print particular lines question
On 2020-08-31 17:03, yary wrote: anonymous variable Would be safe thinking it had the same properties as `$_`?
Re: print particular lines question
I like this better for alpha counter raku -e "for (1..4) { say (BEGIN $ = 'AAA')++ }" with BEGIN, the assignment of AAA happens once. With the earlier ||= it checks each time through the loop. -y On Mon, Aug 31, 2020 at 5:03 PM yary wrote: > Not even a reset- every time there's a $ by itself it is a new/different > anonymous variable. So it is only useful where it is never referred to > anywhere else. > > $ raku -e "for (1..4) { say $++, ' , ', ++$; say 'again- ',$;}" > > 0 , 1 > > again- (Any) > > 1 , 2 > > again- (Any) > > 2 , 3 > > again- (Any) > > 3 , 4 > > again- (Any) > > Hmm, how to make an alpha counter? > > $ raku -e "for (1..4) { say ($ ||= 'AAA')++ }" > > AAA > > AAB > > AAC > > AAD > > There is also anonymous @ and % but I don't have an example off the top of > my head. > -y > > > On Mon, Aug 31, 2020 at 4:57 PM ToddAndMargo via perl6-users < > perl6-users@perl.org> wrote: > >> On 2020-08-31 16:53, ToddAndMargo via perl6-users wrote: >> >>> On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users >> >>> mailto:perl6-users@perl.org>> wrote: >> >>> >> >>> On 2020-08-31 05:53, Brian Duggan wrote: >> >>> > On Monday, August 24, Curt Tilmes wrote: >> >>> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' >> >>> > >> >>> > The -n flag is an option here too: >> >>> > >> >>> > raku -ne '.say if $++ == 3|2|5' Lines.txt >> >>> > >> >>> > Brian >> >>> > >> >>> >> > >> Hi Bill, >> >> Works beatifically! And no bash pipe! >> >> $ raku -ne '.say if $++ == 3|2|5' Lines.txt >> Line 2 >> Line 3 >> Line 5 >> >> What is `$++`? >> >> -T >> >> > >> > On 2020-08-31 16:36, yary wrote: >> >> $ by itself is an anonymous variable, putting ++ after starts it at 0 >> >> (hmm or nil?) and increments up. >> >> >> >> By putting the plus plus first, ++$, it will start at 1, thanks to >> >> pre-increment versus post increment >> >> >> > >> > Hi Yary, >> > >> > Excellent instructions! It is a counter. I found >> > it over on >> > >> > https://docs.raku.org/perl6.html >> > >> > with a search on `$++`. But I had to pick it up >> > from "context" >> > >> > >> > >> > $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++," ", ++$, " ", $i, >> > "\n";}' >> > 0 1 "a" >> > 1 2 "b" >> > 2 3 "c" >> > >> > Question: does the counter restart after its use, or do >> > I need to do it myself? >> > >> > -T >> > >> >> To answer my own question. It resets itself: >> >> $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++, " ", ++$, " ", $i, >> "\n" }; print "\n", $++, "\n";' >> 0 1 "a" >> 1 2 "b" >> 2 3 "c" >> >> 0 >> >> >> >> -- >> ~~ >> Computers are like air conditioners. >> They malfunction when you open windows >> ~~ >> >
Re: print particular lines question
Depends where in your code the $++ is. It may play as global or as local. raku -e 'for 1..3 {say $++}; say $++' On Mon, Aug 31, 2020 at 9:03 PM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > > > adn > > fixed > -- Aureliano Guedes skype: aureliano.guedes contato: (11) 94292-6110 whatsapp +5511942926110
Re: print particular lines question
Not even a reset- every time there's a $ by itself it is a new/different anonymous variable. So it is only useful where it is never referred to anywhere else. $ raku -e "for (1..4) { say $++, ' , ', ++$; say 'again- ',$;}" 0 , 1 again- (Any) 1 , 2 again- (Any) 2 , 3 again- (Any) 3 , 4 again- (Any) Hmm, how to make an alpha counter? $ raku -e "for (1..4) { say ($ ||= 'AAA')++ }" AAA AAB AAC AAD There is also anonymous @ and % but I don't have an example off the top of my head. -y On Mon, Aug 31, 2020 at 4:57 PM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > On 2020-08-31 16:53, ToddAndMargo via perl6-users wrote: > >>> On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users > >>> mailto:perl6-users@perl.org>> wrote: > >>> > >>> On 2020-08-31 05:53, Brian Duggan wrote: > >>> > On Monday, August 24, Curt Tilmes wrote: > >>> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' > >>> > > >>> > The -n flag is an option here too: > >>> > > >>> > raku -ne '.say if $++ == 3|2|5' Lines.txt > >>> > > >>> > Brian > >>> > > >>> > > > Hi Bill, > > Works beatifically! And no bash pipe! > > $ raku -ne '.say if $++ == 3|2|5' Lines.txt > Line 2 > Line 3 > Line 5 > > What is `$++`? > > -T > > > > > On 2020-08-31 16:36, yary wrote: > >> $ by itself is an anonymous variable, putting ++ after starts it at 0 > >> (hmm or nil?) and increments up. > >> > >> By putting the plus plus first, ++$, it will start at 1, thanks to > >> pre-increment versus post increment > >> > > > > Hi Yary, > > > > Excellent instructions! It is a counter. I found > > it over on > > > > https://docs.raku.org/perl6.html > > > > with a search on `$++`. But I had to pick it up > > from "context" > > > > > > > > $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++," ", ++$, " ", $i, > > "\n";}' > > 0 1 "a" > > 1 2 "b" > > 2 3 "c" > > > > Question: does the counter restart after its use, or do > > I need to do it myself? > > > > -T > > > > To answer my own question. It resets itself: > > $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++, " ", ++$, " ", $i, > "\n" }; print "\n", $++, "\n";' > 0 1 "a" > 1 2 "b" > 2 3 "c" > > 0 > > > > -- > ~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~ >
Re: print particular lines question
adn fixed
Re: print particular lines question
On 2020-08-31 16:57, ToddAndMargo via perl6-users wrote: On 2020-08-31 16:53, ToddAndMargo via perl6-users wrote: On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: On 2020-08-31 05:53, Brian Duggan wrote: > On Monday, August 24, Curt Tilmes wrote: >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' > > The -n flag is an option here too: > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > Brian > Hi Bill, Works beatifically! And no bash pipe! $ raku -ne '.say if $++ == 3|2|5' Lines.txt Line 2 Line 3 Line 5 What is `$++`? -T On 2020-08-31 16:36, yary wrote: $ by itself is an anonymous variable, putting ++ after starts it at 0 (hmm or nil?) and increments up. By putting the plus plus first, ++$, it will start at 1, thanks to pre-increment versus post increment Hi Yary, Excellent instructions! It is a counter. I found it over on https://docs.raku.org/perl6.html with a search on `$++`. But I had to pick it up from "context" $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++," ", ++$, " ", $i, "\n";}' 0 1 "a" 1 2 "b" 2 3 "c" Question: does the counter restart after its use, or do I need to do it myself? -T To answer my own question. It resets itself: $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++, " ", ++$, " ", $i, "\n" }; print "\n", $++, "\n";' 0 1 "a" 1 2 "b" 2 3 "c" 0 perl6.++.counters.txt ++ counters: $++ adn ++$ are both anonymous variables `$++` is a counter that start at zero and increments by 1 `++$` is a counter that start at one and increments by 1 and the reset themselves. For example: $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++, " ", ++$, " ", $i, "\n" }; print "\n", $++, "\n";' 0 1 "a" 1 2 "b" 2 3 "c" 0
Re: print particular lines question
On 2020-08-31 16:53, ToddAndMargo via perl6-users wrote: On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: On 2020-08-31 05:53, Brian Duggan wrote: > On Monday, August 24, Curt Tilmes wrote: >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' > > The -n flag is an option here too: > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > Brian > Hi Bill, Works beatifically! And no bash pipe! $ raku -ne '.say if $++ == 3|2|5' Lines.txt Line 2 Line 3 Line 5 What is `$++`? -T On 2020-08-31 16:36, yary wrote: $ by itself is an anonymous variable, putting ++ after starts it at 0 (hmm or nil?) and increments up. By putting the plus plus first, ++$, it will start at 1, thanks to pre-increment versus post increment Hi Yary, Excellent instructions! It is a counter. I found it over on https://docs.raku.org/perl6.html with a search on `$++`. But I had to pick it up from "context" $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++," ", ++$, " ", $i, "\n";}' 0 1 "a" 1 2 "b" 2 3 "c" Question: does the counter restart after its use, or do I need to do it myself? -T To answer my own question. It resets itself: $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++, " ", ++$, " ", $i, "\n" }; print "\n", $++, "\n";' 0 1 "a" 1 2 "b" 2 3 "c" 0 -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: print particular lines question
On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: On 2020-08-31 05:53, Brian Duggan wrote: > On Monday, August 24, Curt Tilmes wrote: >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' > > The -n flag is an option here too: > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > Brian > Hi Bill, Works beatifically! And no bash pipe! $ raku -ne '.say if $++ == 3|2|5' Lines.txt Line 2 Line 3 Line 5 What is `$++`? -T On 2020-08-31 16:36, yary wrote: $ by itself is an anonymous variable, putting ++ after starts it at 0 (hmm or nil?) and increments up. By putting the plus plus first, ++$, it will start at 1, thanks to pre-increment versus post increment Hi Yary, Excellent instructions! It is a counter. I found it over on https://docs.raku.org/perl6.html with a search on `$++`. But I had to pick it up from "context" $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++," ", ++$, " ", $i, "\n";}' 0 1 "a" 1 2 "b" 2 3 "c" Question: does the counter restart after its use, or do I need to do it myself? -T -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: print particular lines question
Answering my own question, the operator sets the type of $. That's what gradual typing is all about! $ seq 5 | raku -ne "say $++" 0 1 2 3 4 $ seq 5 | raku -ne "say $ ~= 'Hi' " Hi HiHi HiHiHi HiHiHiHi HiHiHiHiHi $ seq 5 | raku -ne "say $++, $ ~= ' Hi' " 0 Hi 1 Hi Hi 2 Hi Hi Hi 3 Hi Hi Hi Hi 4 Hi Hi Hi Hi Hi -y On Mon, Aug 31, 2020 at 4:39 PM Aureliano Guedes wrote: > Basically : > > $ raku -e 'my $a = 1; say ++$a; say $a' > 2 > 2 > $ raku -e 'my $a = 1; say $a++; say $a' > 1 > 2 > > On Mon, Aug 31, 2020 at 8:36 PM yary wrote: > >> $ by itself is an anonymous variable, putting ++ after starts it at 0 >> (hmm or nil?) and increments up. >> >> By putting the plus plus first, ++$, it will start at 1, thanks to >> pre-increment versus post increment >> >> On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users < >> perl6-users@perl.org> wrote: >> >>> On 2020-08-31 05:53, Brian Duggan wrote: >>> > On Monday, August 24, Curt Tilmes wrote: >>> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' >>> > >>> > The -n flag is an option here too: >>> > >>> > raku -ne '.say if $++ == 3|2|5' Lines.txt >>> > >>> > Brian >>> > >>> >>> Hi Bill, >>> >>> Works beatifically! And no bash pipe! >>> >>> $ raku -ne '.say if $++ == 3|2|5' Lines.txt >>> Line 2 >>> Line 3 >>> Line 5 >>> >>> What is `$++`? >>> >>> -T >>> >> > > -- > Aureliano Guedes > skype: aureliano.guedes > contato: (11) 94292-6110 > whatsapp +5511942926110 >
Re: print particular lines question
Basically : $ raku -e 'my $a = 1; say ++$a; say $a' 2 2 $ raku -e 'my $a = 1; say $a++; say $a' 1 2 On Mon, Aug 31, 2020 at 8:36 PM yary wrote: > $ by itself is an anonymous variable, putting ++ after starts it at 0 (hmm > or nil?) and increments up. > > By putting the plus plus first, ++$, it will start at 1, thanks to > pre-increment versus post increment > > On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users < > perl6-users@perl.org> wrote: > >> On 2020-08-31 05:53, Brian Duggan wrote: >> > On Monday, August 24, Curt Tilmes wrote: >> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' >> > >> > The -n flag is an option here too: >> > >> > raku -ne '.say if $++ == 3|2|5' Lines.txt >> > >> > Brian >> > >> >> Hi Bill, >> >> Works beatifically! And no bash pipe! >> >> $ raku -ne '.say if $++ == 3|2|5' Lines.txt >> Line 2 >> Line 3 >> Line 5 >> >> What is `$++`? >> >> -T >> > -- Aureliano Guedes skype: aureliano.guedes contato: (11) 94292-6110 whatsapp +5511942926110
Re: print particular lines question
$ by itself is an anonymous variable, putting ++ after starts it at 0 (hmm or nil?) and increments up. By putting the plus plus first, ++$, it will start at 1, thanks to pre-increment versus post increment On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > On 2020-08-31 05:53, Brian Duggan wrote: > > On Monday, August 24, Curt Tilmes wrote: > >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' > > > > The -n flag is an option here too: > > > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > > > Brian > > > > Hi Bill, > > Works beatifically! And no bash pipe! > > $ raku -ne '.say if $++ == 3|2|5' Lines.txt > Line 2 > Line 3 > Line 5 > > What is `$++`? > > -T >
Re: print particular lines question
On 2020-08-31 05:53, Brian Duggan wrote: On Monday, August 24, Curt Tilmes wrote: $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' The -n flag is an option here too: raku -ne '.say if $++ == 3|2|5' Lines.txt Brian Hi Bill, Works beatifically! And no bash pipe! $ raku -ne '.say if $++ == 3|2|5' Lines.txt Line 2 Line 3 Line 5 What is `$++`? -T
Re: print particular lines question
> Not getting back line #11 with perl -ne 'print if $. =~ /\b[3 2 5 11]\b/' test_lines.txt Right, as the char class contains , 1, 2, 3 and 5. I guess alternatives perl -ne 'print if $. =~ /\b(1|5|3|11)\b/' /tmp/lines.txt line: 1 line: 3 line: 5 line: 11 From: William Michels Sent: Monday, August 31, 2020 10:28 AM To: Brian Duggan Cc: Andy Bach ; perl6-users Subject: Re: print particular lines question How would P5 handle line numbers > 10 ? Not getting back line #11 with the P5 examples below: $ raku -ne '.say if ++$ == 3|2|5|11' test_lines.txt Line 2 Line 3 Line 5 Line 11 ~$ perl -ne 'print if $. =~ /\b[3 2 5 11]\b/' test_lines.txt Line 1 Line 2 Line 3 Line 5 ~$ perl -ne 'print if $. =~ /\b[3,2, 5, 11]\b/' test_lines.txt Line 1 Line 2 Line 3 Line 5 On Mon, Aug 31, 2020 at 8:17 AM Brian Duggan wrote: > > On Monday, August 31, Andy Bach wrote: > > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > > > OT, maybe, but is > > perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt > > > > or > > perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt > > > > the best you can do in P5? > > I can't think of anything better :-) > > Brian
Re: print particular lines question
Thanks Yary! So that means Brian's answer in Raku can use the smartmatch operator instead of the "==". Good to know! ~$ raku -ne '.say if ++$ ~~ 3|5|11' test_lines.txt Line 3 Line 5 Line 11 On Mon, Aug 31, 2020 at 8:47 AM yary wrote: > > Aww don't you remember Raku's earliest(?) contribution to Perl? I was so > happy when this arrived, and sad over its subsequent neglect > > perl -ne 'no warnings "experimental"; print if $. ~~ [3,5,11]' line0-10.txt > > > -y > > > On Mon, Aug 31, 2020 at 8:28 AM William Michels via perl6-users > wrote: >> >> How would P5 handle line numbers > 10 ? Not getting back line #11 with >> the P5 examples below: >> >> $ raku -ne '.say if ++$ == 3|2|5|11' test_lines.txt >> Line 2 >> Line 3 >> Line 5 >> Line 11 >> >> ~$ perl -ne 'print if $. =~ /\b[3 2 5 11]\b/' test_lines.txt >> Line 1 >> Line 2 >> Line 3 >> Line 5 >> >> ~$ perl -ne 'print if $. =~ /\b[3,2, 5, 11]\b/' test_lines.txt >> Line 1 >> Line 2 >> Line 3 >> Line 5 >> >> On Mon, Aug 31, 2020 at 8:17 AM Brian Duggan wrote: >> > >> > On Monday, August 31, Andy Bach wrote: >> > > > raku -ne '.say if $++ == 3|2|5' Lines.txt >> > > >> > > OT, maybe, but is >> > > perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt >> > > >> > > or >> > > perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt >> > > >> > > the best you can do in P5? >> > >> > I can't think of anything better :-) >> > >> > Brian
Re: print particular lines question
Aww don't you remember Raku's earliest(?) contribution to Perl? I was so happy when this arrived, and sad over its subsequent neglect perl -ne 'no warnings "experimental"; print if $. ~~ [3,5,11]' line0-10.txt -y On Mon, Aug 31, 2020 at 8:28 AM William Michels via perl6-users < perl6-users@perl.org> wrote: > How would P5 handle line numbers > 10 ? Not getting back line #11 with > the P5 examples below: > > $ raku -ne '.say if ++$ == 3|2|5|11' test_lines.txt > Line 2 > Line 3 > Line 5 > Line 11 > > ~$ perl -ne 'print if $. =~ /\b[3 2 5 11]\b/' test_lines.txt > Line 1 > Line 2 > Line 3 > Line 5 > > ~$ perl -ne 'print if $. =~ /\b[3,2, 5, 11]\b/' test_lines.txt > Line 1 > Line 2 > Line 3 > Line 5 > > On Mon, Aug 31, 2020 at 8:17 AM Brian Duggan wrote: > > > > On Monday, August 31, Andy Bach wrote: > > > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > > > > > OT, maybe, but is > > > perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt > > > > > > or > > > perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt > > > > > > the best you can do in P5? > > > > I can't think of anything better :-) > > > > Brian >
Re: print particular lines question
How would P5 handle line numbers > 10 ? Not getting back line #11 with the P5 examples below: $ raku -ne '.say if ++$ == 3|2|5|11' test_lines.txt Line 2 Line 3 Line 5 Line 11 ~$ perl -ne 'print if $. =~ /\b[3 2 5 11]\b/' test_lines.txt Line 1 Line 2 Line 3 Line 5 ~$ perl -ne 'print if $. =~ /\b[3,2, 5, 11]\b/' test_lines.txt Line 1 Line 2 Line 3 Line 5 On Mon, Aug 31, 2020 at 8:17 AM Brian Duggan wrote: > > On Monday, August 31, Andy Bach wrote: > > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > > > OT, maybe, but is > > perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt > > > > or > > perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt > > > > the best you can do in P5? > > I can't think of anything better :-) > > Brian
Re: print particular lines question
On Monday, August 31, Andy Bach wrote: > > raku -ne '.say if $++ == 3|2|5' Lines.txt > > OT, maybe, but is > perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt > > or > perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt > > the best you can do in P5? I can't think of anything better :-) Brian
Re: print particular lines question
> raku -ne '.say if $++ == 3|2|5' Lines.txt OT, maybe, but is perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt or perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt the best you can do in P5? a Andy Bach, BS, MSCMECFA Systems Mangler Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> Voice: (608) 261-5738, Cell: (608) 658-1890 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". https://martinfowler.com/bliki/TwoHardThings.html From: Brian Duggan Sent: Monday, August 31, 2020 7:53 AM To: Curt Tilmes Cc: perl6-users Subject: Re: print particular lines question On Monday, August 24, Curt Tilmes wrote: > $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' The -n flag is an option here too: raku -ne '.say if $++ == 3|2|5' Lines.txt Brian
Re: print particular lines question
On Monday, August 24, Curt Tilmes wrote: > $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' The -n flag is an option here too: raku -ne '.say if $++ == 3|2|5' Lines.txt Brian
Re: Seq whitespace sensitivity? (was Re: print particular lines question)
Dear Tobias (and Sean), I opened a Github issue: https://github.com/rakudo/rakudo/issues/3881 On Wed, Aug 26, 2020 at 12:12 PM Tobias Boege wrote: > On Wed, 26 Aug 2020, Tobias Boege wrote: > > Observe: > > > > > 1 ...^ 20 > > (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > > > > > 1 ... ^20 # actually C«1 ... (0..19)» > > (1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > > > > The documentation [1] states that the C«...» infix is list-associative > > and while I have never seen an example of that (including in that docs > > page), it would explain why it happily takes in your list (1) and then > > your list (0 .. 19) and concatenates them into a sequence, without > > applying any of the usual sequence operator magic. > > And I must correct myself. The associativity has nothing to do with this. > I don't know where my mind was when I wrote that. From the documtation, > I would blame the slurpy argument **@ for that behavior of just taking in > lists and effectively iterating them into a new Seq, and in Rakudo it is > apparently this special candidate: > > # > https://github.com/rakudo/rakudo/blob/e2855aa/src/core.c/operators.pm6#L129 > multi sub infix:<...>(\a, Mu \b) { > Seq.new(SEQUENCE(a, b)) > } > > Best, > Tobias >
Re: Seq whitespace sensitivity? (was Re: print particular lines question)
On Wed, 26 Aug 2020, Tobias Boege wrote: > Observe: > > > 1 ...^ 20 > (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > > > 1 ... ^20 # actually C«1 ... (0..19)» > (1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > > The documentation [1] states that the C«...» infix is list-associative > and while I have never seen an example of that (including in that docs > page), it would explain why it happily takes in your list (1) and then > your list (0 .. 19) and concatenates them into a sequence, without > applying any of the usual sequence operator magic. And I must correct myself. The associativity has nothing to do with this. I don't know where my mind was when I wrote that. From the documtation, I would blame the slurpy argument **@ for that behavior of just taking in lists and effectively iterating them into a new Seq, and in Rakudo it is apparently this special candidate: # https://github.com/rakudo/rakudo/blob/e2855aa/src/core.c/operators.pm6#L129 multi sub infix:<...>(\a, Mu \b) { Seq.new(SEQUENCE(a, b)) } Best, Tobias
Re: Seq whitespace sensitivity? (was Re: print particular lines question)
On Wed, Aug 26, 2020 at 10:33 AM Tobias Boege wrote: > > On Wed, 26 Aug 2020, William Michels via perl6-users wrote: > > > They can be pretty great, especially when combined with the magic op= > > > operators that (in essence) know about identity elements. I've done a > > > few challenges on the Code Golf Stackexchange site where I wanted an > > > infinite sequence like this: > > > > > > 0, 1, -2, 3, -4, 5, -6, ... > > > > > > It took me a while to realize this can be expressed in Raku simply as: > > > > > > { $++ * ($ *= -1) } ... * > > > > > > > Hi Sean, that's a neat solution! I seem to have found an oddity though > > (whitespace sensitivity). In the REPL: > > > > > say { $++ * ($ *= -1) } ...21 > > (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20 21) > > > say { $++ * ($ *= -1) } ...^21 > > (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20) > > > say { $++ * ($ *= -1) } ... 21 > > (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20 21) > > > say { $++ * ($ *= -1) } ... ^21 > > (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) > > > > I would have expected the last line of code (whitespace between "..." > > and "^21") to give the same answer as the first three. Any ideas? > > > > The difference is likely to come from the fact that "^20" as a term is > a shorthand for the range "0..^20", while "...^" is the sequence operator > with exclusive endpoint. Placement of whitespace will dictate where the > little hat attaches to and thus change the meaning of the statement. > > Observe: > > > 1 ...^ 20 > (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > > > 1 ... ^20 # actually C«1 ... (0..19)» > (1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > > The documentation [1] states that the C«...» infix is list-associative > and while I have never seen an example of that (including in that docs > page), it would explain why it happily takes in your list (1) and then > your list (0 .. 19) and concatenates them into a sequence, without > applying any of the usual sequence operator magic. > > When you write "1 ...^20" I suppose that longest-token matching prefers > the former interpretation as it makes the infix token longer. > > Best, > Tobias > > [1] https://docs.raku.org/language/operators#index-entry-..._operators > > -- > "There's an old saying: Don't change anything... ever!" -- Mr. Monk Thank you, Tobias! Here's my take (REPL, below): > 1...20 (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) > 1... 20 (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) > 1...^20 (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > 1... ^20 (1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) WOW. I never would have expected the last line of code above to return a sequence starting "1, 0, 1 ..." up to 19. Would I ever want that sequence? Couldn't I get that sequence just as easily by asking for a sequence of (-1 ... ^20), and then calling abs() on each element (using hyper)? See below: > (-1... ^20)>>.abs (1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > Anyway, I opened a Github issue, and (like yourself here), Jonathan has graciously replied. Feel free to chime in at: https://github.com/rakudo/rakudo/issues/3881 Thanks again, Bill.
Re: Seq whitespace sensitivity? (was Re: print particular lines question)
On Wed, 26 Aug 2020, William Michels via perl6-users wrote: > > They can be pretty great, especially when combined with the magic op= > > operators that (in essence) know about identity elements. I've done a few > > challenges on the Code Golf Stackexchange site where I wanted an infinite > > sequence like this: > > > > 0, 1, -2, 3, -4, 5, -6, ... > > > > It took me a while to realize this can be expressed in Raku simply as: > > > > { $++ * ($ *= -1) } ... * > > > > Hi Sean, that's a neat solution! I seem to have found an oddity though > (whitespace sensitivity). In the REPL: > > > say { $++ * ($ *= -1) } ...21 > (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20 21) > > say { $++ * ($ *= -1) } ...^21 > (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20) > > say { $++ * ($ *= -1) } ... 21 > (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20 21) > > say { $++ * ($ *= -1) } ... ^21 > (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) > > I would have expected the last line of code (whitespace between "..." > and "^21") to give the same answer as the first three. Any ideas? > The difference is likely to come from the fact that "^20" as a term is a shorthand for the range "0..^20", while "...^" is the sequence operator with exclusive endpoint. Placement of whitespace will dictate where the little hat attaches to and thus change the meaning of the statement. Observe: > 1 ...^ 20 (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > 1 ... ^20 # actually C«1 ... (0..19)» (1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) The documentation [1] states that the C«...» infix is list-associative and while I have never seen an example of that (including in that docs page), it would explain why it happily takes in your list (1) and then your list (0 .. 19) and concatenates them into a sequence, without applying any of the usual sequence operator magic. When you write "1 ...^20" I suppose that longest-token matching prefers the former interpretation as it makes the infix token longer. Best, Tobias [1] https://docs.raku.org/language/operators#index-entry-..._operators -- "There's an old saying: Don't change anything... ever!" -- Mr. Monk
Seq whitespace sensitivity? (was Re: print particular lines question)
> They can be pretty great, especially when combined with the magic op= > operators that (in essence) know about identity elements. I've done a few > challenges on the Code Golf Stackexchange site where I wanted an infinite > sequence like this: > > 0, 1, -2, 3, -4, 5, -6, ... > > It took me a while to realize this can be expressed in Raku simply as: > > { $++ * ($ *= -1) } ... * > Hi Sean, that's a neat solution! I seem to have found an oddity though (whitespace sensitivity). In the REPL: > say { $++ * ($ *= -1) } ...21 (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20 21) > say { $++ * ($ *= -1) } ...^21 (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20) > say { $++ * ($ *= -1) } ... 21 (0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20 21) > say { $++ * ($ *= -1) } ... ^21 (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) I would have expected the last line of code (whitespace between "..." and "^21") to give the same answer as the first three. Any ideas? Best, Bill.
Re: print particular lines question
On 2020-08-24 20:30, ToddAndMargo via perl6-users wrote: On Mon, Aug 24, 2020 at 11:08 PM ToddAndMargo via perl6-users wrote: On 2020-08-24 19:35, ToddAndMargo via perl6-users wrote: Hi All, I seems I should know how to do this, but I am drawing a blank. $ cat Lines.txt | raku -ne 'say $_;' Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 I want to print liens 1, 3, and 7. Assigning `my @x=$_.lines` puts everything into $x[0] Many thanks, -T This is what I have so far: $ cat Lines.txt Line 0 Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 $ cat Lines.txt | raku -e ' my @x=$*IN.lines; for @x[3,2,5] {say $_};' Line 3 Line 2 Line 5 is there a quicker way to get to the point? Many thanks, -T On 2020-08-24 20:24, Curt Tilmes wrote: $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' Love it! Thank you! I suppose I'd better add I was looking for a improvement ... | sed -n 'x,yp' For my remaining bash programs
Re: print particular lines question
> On Aug 25, 2020, at 4:13 PM, yary wrote: > > > Now, does anyone have a simpler way than using the ".map" above? > > There were a few in the thread! > > Here's my golfing, unlike the others, this preserves the order of the lines > (which may or may not be desired) > > raku -ne '.say if $++ == any 6,3,1' line0-10.txt —snip— That technique is called the "anonymous state variable", and is documented here: https://docs.raku.org/language/variables#The_$_variable I especially favor the `-n` flag for this problem, because we con’t have to “slurp” a possibly-large file into memory, and because it enables the `UNIX filter` behavior that allows us to specify the filename as a command-line argument, instead of having to pipe it in with `cat` (or `type` on Win32). My version is almost identical, but changing to pre-increment allows you to specify the line numbers with the more natural numbering: raku -ne '.say if ++$ == any(1,3,7);' Lines.txt Line 1 Line 3 Line 7 -- Bruce Gray (Util of PerlMonks)
Re: print particular lines question
Funny, I didn't see anyone compute an offset. Could you point it out? I'm interested. Anyway, I golfed it a little bit with a whatever-star. Below you can preserve or rearrange the order of returned lines (#1, and #2). And you offset using whatever value you'd like (#3): #1 ~$ raku -e '$*IN.lines[ (1,3,7).map(*-1) ].join("\n").put;' < Lines.txt Line 1 Line 3 Line 7 #2 ~$ raku -e '$*IN.lines[ (1,7,3).map(*-1) ].join("\n").put;' < Lines.txt Line 1 Line 7 Line 3 #3 ~$ raku -e '$*IN.lines[ (1,3,7).map(*+3) ].join("\n").put;' < Lines.txt Line 5 Line 7 Line 11 HTH, Bill. On Tue, Aug 25, 2020 at 2:13 PM yary wrote: > > Now, does anyone have a simpler way than using the ".map" above? > > There were a few in the thread! > > Here's my golfing, unlike the others, this preserves the order of the > lines (which may or may not be desired) > > raku -ne '.say if $++ == any 6,3,1' line0-10.txt > > -y > > > On Tue, Aug 25, 2020 at 12:03 PM William Michels via perl6-users < > perl6-users@perl.org> wrote: > >> If Todd wants to print lines containing "Line 1", "Line 3", and "Line 7", >> he's going to have to correct for zero-indexing: >> >> user@book:~$ raku -e '$*IN.lines[ 1,3,7 ].join("\n").put;' < Lines.txt >> Line 2 >> Line 4 >> Line 8 >> >> #Below: subtracting one from (1,3,7) gives the return he wants: >> >> user@book:~$ raku -e '$*IN.lines[ (1,3,7).map: { $_ - 1 } >> ].join("\n").put;' < Lines.txt >> Line 1 >> Line 3 >> Line 7 >> >> Now, does anyone have a simpler way than using the ".map" above? >> >> HTH, Bill. >> >> >> >> On Tue, Aug 25, 2020 at 10:46 AM Andy Bach >> wrote: >> >>> Ah, I see, the -n reads a line and then my lines on $*IN starts with the >>> next one >>> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e >>> "my @x = $*IN.lines(); say @x[0,1,7,3]; " >>> (Line 0 Line 1 Line 7 Line 3) >>> >>> and so $*IN is the default for lines() >>> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e >>> "my @x = lines(); say @x[0,1,7,3]; " >>> (Line 0 Line 1 Line 7 Line 3) >>> >>> This hangs, with and without the -n >>> C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = >>> $*IN.lines(); say @x[0,1,7,3]; " lines.txt >>> >>> Though: >>> C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = lines(); >>> say @x[0,1,7,3]; " lines.txt >>> (Line 1 Line 2 Line 8 Line 4) >>> Cannot do 'get' on a handle in binary mode >>> in block at -e line 1 >>> >>> a >>> >>> Andy Bach, BS, MSCMECFA >>> Systems Mangler >>> Internet: andy_b...@wiwb.uscourts.gov >>> Voice: (608) 261-5738, Cell: (608) 658-1890 >>> >>> "The three great problems of computer science: >>> compiler complexity and 'off-by-one' errors". >>> https://martinfowler.com/bliki/TwoHardThings.html >>> >>> -- >>> *From:* Andy Bach >>> *Sent:* Tuesday, August 25, 2020 12:18 PM >>> *To:* Parrot Raiser <1parr...@gmail.com> >>> *Cc:* perl6-users ; ToddAndMargo < >>> toddandma...@zoho.com> >>> *Subject:* Re: print particular lines question >>> >>> On Win10 >>> C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >>> "say lines()[1,7,3]; " >>> (Line 2 Line 8 Line 4) >>> (Line 11 Nil Nil) >>> >>> C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >>> "say lines()[1,7,3].join(qq~\n~); " >>> Line 2 >>> Line 8 >>> Line 4 >>> Use of Nil in string context >>> in block at -e line 1 >>> Use of Nil in string context >>> in block at -e line 1 >>> Line 11 >>> >>> and, speaking of that off by one problem ... lines.txt does start with >>> "line 0" >>> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >>> "my @x = $*IN.lines(); say @x[0,1,7,3]; " >>> (Line 1 Line 2 Line 8 Line 4) >>> >>> a >>> >>> Andy Bach, BS, MSCMECFA >>> Systems Mangler >>> Internet: andy_b...@wiwb.uscourts.gov >>> Voice: (608) 261-5738, Cell: (
Re: print particular lines question
On Tue, Aug 25, 2020 at 2:31 PM Andy Bach wrote: > Pretty cool - I didn't know about the bare "$" as a magic state var. > They can be pretty great, especially when combined with the magic op= operators that (in essence) know about identity elements. I've done a few challenges on the Code Golf Stackexchange site where I wanted an infinite sequence like this: 0, 1, -2, 3, -4, 5, -6, ... It took me a while to realize this can be expressed in Raku simply as: { $++ * ($ *= -1) } ... *
Re: print particular lines question
> this preserves the order of the lines (which may or may not be desired) raku -ne '.say if $++ == any 6,3,1' line0-10.txt So there is no "$."/current input line # built-in? I started with # cat /tmp/lines.txt | perl -ne 'print if $. == 1 or $. == 3 or $. == 7' but couldn't find a $. raku-ism. https://docs.raku.org/language/variables#Special_variables Pretty cool - I didn't know about the bare "$" as a magic state var. a Andy Bach, BS, MSCMECFA Systems Mangler Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> Voice: (608) 261-5738, Cell: (608) 658-1890 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". https://martinfowler.com/bliki/TwoHardThings.html From: yary Sent: Tuesday, August 25, 2020 4:13 PM To: William Michels Cc: perl6-users ; Parrot Raiser <1parr...@gmail.com>; ToddAndMargo ; Andy Bach ; Curt Tilmes Subject: Re: print particular lines question > Now, does anyone have a simpler way than using the ".map" above? There were a few in the thread! Here's my golfing, unlike the others, this preserves the order of the lines (which may or may not be desired) raku -ne '.say if $++ == any 6,3,1' line0-10.txt -y On Tue, Aug 25, 2020 at 12:03 PM William Michels via perl6-users mailto:perl6-users@perl.org>> wrote: If Todd wants to print lines containing "Line 1", "Line 3", and "Line 7", he's going to have to correct for zero-indexing: user@book:~$ raku -e '$*IN.lines[ 1,3,7 ].join("\n").put;' < Lines.txt Line 2 Line 4 Line 8 #Below: subtracting one from (1,3,7) gives the return he wants: user@book:~$ raku -e '$*IN.lines[ (1,3,7).map: { $_ - 1 } ].join("\n").put;' < Lines.txt Line 1 Line 3 Line 7 Now, does anyone have a simpler way than using the ".map" above? HTH, Bill. On Tue, Aug 25, 2020 at 10:46 AM Andy Bach mailto:andy_b...@wiwb.uscourts.gov>> wrote: Ah, I see, the -n reads a line and then my lines on $*IN starts with the next one C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my @x = $*IN.lines(); say @x[0,1,7,3]; " (Line 0 Line 1 Line 7 Line 3) and so $*IN is the default for lines() C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my @x = lines(); say @x[0,1,7,3]; " (Line 0 Line 1 Line 7 Line 3) This hangs, with and without the -n C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = $*IN.lines(); say @x[0,1,7,3]; " lines.txt Though: C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = lines(); say @x[0,1,7,3]; " lines.txt (Line 1 Line 2 Line 8 Line 4) Cannot do 'get' on a handle in binary mode in block at -e line 1 a Andy Bach, BS, MSCMECFA Systems Mangler Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> Voice: (608) 261-5738, Cell: (608) 658-1890 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". https://martinfowler.com/bliki/TwoHardThings.html From: Andy Bach mailto:andy_b...@wiwb.uscourts.gov>> Sent: Tuesday, August 25, 2020 12:18 PM To: Parrot Raiser <1parr...@gmail.com<mailto:1parr...@gmail.com>> Cc: perl6-users mailto:perl6-users@perl.org>>; ToddAndMargo mailto:toddandma...@zoho.com>> Subject: Re: print particular lines question On Win10 C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "say lines()[1,7,3]; " (Line 2 Line 8 Line 4) (Line 11 Nil Nil) C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "say lines()[1,7,3].join(qq~\n~); " Line 2 Line 8 Line 4 Use of Nil in string context in block at -e line 1 Use of Nil in string context in block at -e line 1 Line 11 and, speaking of that off by one problem ... lines.txt does start with "line 0" C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = $*IN.lines(); say @x[0,1,7,3]; " (Line 1 Line 2 Line 8 Line 4) a Andy Bach, BS, MSCMECFA Systems Mangler Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> Voice: (608) 261-5738, Cell: (608) 658-1890 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". https://martinfowler.com/bliki/TwoHardThings.html From: Parrot Raiser <1parr...@gmail.com<mailto:1parr...@gmail.com>> Sent: Tuesday, August 25, 2020 11:22 AM To: Andy Bach mailto:andy_b...@wiwb.uscourts.gov>> Cc: perl6-users mailto:perl6-users@perl.org>>; ToddAndMargo mailto:toddandma...@zoho.com>> Subject: Re: print particular lines question That will golf a little (and i
Re: print particular lines question
> Now, does anyone have a simpler way than using the ".map" above? There were a few in the thread! Here's my golfing, unlike the others, this preserves the order of the lines (which may or may not be desired) raku -ne '.say if $++ == any 6,3,1' line0-10.txt -y On Tue, Aug 25, 2020 at 12:03 PM William Michels via perl6-users < perl6-users@perl.org> wrote: > If Todd wants to print lines containing "Line 1", "Line 3", and "Line 7", > he's going to have to correct for zero-indexing: > > user@book:~$ raku -e '$*IN.lines[ 1,3,7 ].join("\n").put;' < Lines.txt > Line 2 > Line 4 > Line 8 > > #Below: subtracting one from (1,3,7) gives the return he wants: > > user@book:~$ raku -e '$*IN.lines[ (1,3,7).map: { $_ - 1 } > ].join("\n").put;' < Lines.txt > Line 1 > Line 3 > Line 7 > > Now, does anyone have a simpler way than using the ".map" above? > > HTH, Bill. > > > > On Tue, Aug 25, 2020 at 10:46 AM Andy Bach > wrote: > >> Ah, I see, the -n reads a line and then my lines on $*IN starts with the >> next one >> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my >> @x = $*IN.lines(); say @x[0,1,7,3]; " >> (Line 0 Line 1 Line 7 Line 3) >> >> and so $*IN is the default for lines() >> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my >> @x = lines(); say @x[0,1,7,3]; " >> (Line 0 Line 1 Line 7 Line 3) >> >> This hangs, with and without the -n >> C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = >> $*IN.lines(); say @x[0,1,7,3]; " lines.txt >> >> Though: >> C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = lines(); >> say @x[0,1,7,3]; " lines.txt >> (Line 1 Line 2 Line 8 Line 4) >> Cannot do 'get' on a handle in binary mode >> in block at -e line 1 >> >> a >> >> Andy Bach, BS, MSCMECFA >> Systems Mangler >> Internet: andy_b...@wiwb.uscourts.gov >> Voice: (608) 261-5738, Cell: (608) 658-1890 >> >> "The three great problems of computer science: >> compiler complexity and 'off-by-one' errors". >> https://martinfowler.com/bliki/TwoHardThings.html >> >> -- >> *From:* Andy Bach >> *Sent:* Tuesday, August 25, 2020 12:18 PM >> *To:* Parrot Raiser <1parr...@gmail.com> >> *Cc:* perl6-users ; ToddAndMargo < >> toddandma...@zoho.com> >> *Subject:* Re: print particular lines question >> >> On Win10 >> C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >> "say lines()[1,7,3]; " >> (Line 2 Line 8 Line 4) >> (Line 11 Nil Nil) >> >> C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >> "say lines()[1,7,3].join(qq~\n~); " >> Line 2 >> Line 8 >> Line 4 >> Use of Nil in string context >> in block at -e line 1 >> Use of Nil in string context >> in block at -e line 1 >> Line 11 >> >> and, speaking of that off by one problem ... lines.txt does start with >> "line 0" >> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >> "my @x = $*IN.lines(); say @x[0,1,7,3]; " >> (Line 1 Line 2 Line 8 Line 4) >> >> a >> >> Andy Bach, BS, MSCMECFA >> Systems Mangler >> Internet: andy_b...@wiwb.uscourts.gov >> Voice: (608) 261-5738, Cell: (608) 658-1890 >> >> "The three great problems of computer science: >> compiler complexity and 'off-by-one' errors". >> https://martinfowler.com/bliki/TwoHardThings.html >> >> -- >> *From:* Parrot Raiser <1parr...@gmail.com> >> *Sent:* Tuesday, August 25, 2020 11:22 AM >> *To:* Andy Bach >> *Cc:* perl6-users ; ToddAndMargo < >> toddandma...@zoho.com> >> *Subject:* Re: print particular lines question >> >> That will golf a little (and improve it) to: >> >> $ raku -e '.say for lines()[3,2,5]' lines.txt >> >> but you have to remember that it's zero-based. I used the first sample >> file and got >> Line 4 >> Line 3 >> Line 6 >> >> "The three great problems of computer science: compiler complexity and >> 'off-by-one' errors". >> >> >> On 8/25/20, Andy Bach wrote: >> >> Assigning `my @x=$_.lines` puts everything into $x[0] >> > >> > Trying
Re: print particular lines question
If Todd wants to print lines containing "Line 1", "Line 3", and "Line 7", he's going to have to correct for zero-indexing: user@book:~$ raku -e '$*IN.lines[ 1,3,7 ].join("\n").put;' < Lines.txt Line 2 Line 4 Line 8 #Below: subtracting one from (1,3,7) gives the return he wants: user@book:~$ raku -e '$*IN.lines[ (1,3,7).map: { $_ - 1 } ].join("\n").put;' < Lines.txt Line 1 Line 3 Line 7 Now, does anyone have a simpler way than using the ".map" above? HTH, Bill. On Tue, Aug 25, 2020 at 10:46 AM Andy Bach wrote: > Ah, I see, the -n reads a line and then my lines on $*IN starts with the > next one > C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my > @x = $*IN.lines(); say @x[0,1,7,3]; " > (Line 0 Line 1 Line 7 Line 3) > > and so $*IN is the default for lines() > C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my > @x = lines(); say @x[0,1,7,3]; " > (Line 0 Line 1 Line 7 Line 3) > > This hangs, with and without the -n > C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = > $*IN.lines(); say @x[0,1,7,3]; " lines.txt > > Though: > C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = lines(); > say @x[0,1,7,3]; " lines.txt > (Line 1 Line 2 Line 8 Line 4) > Cannot do 'get' on a handle in binary mode > in block at -e line 1 > > a > > Andy Bach, BS, MSCMECFA > Systems Mangler > Internet: andy_b...@wiwb.uscourts.gov > Voice: (608) 261-5738, Cell: (608) 658-1890 > > "The three great problems of computer science: > compiler complexity and 'off-by-one' errors". > https://martinfowler.com/bliki/TwoHardThings.html > > -- > *From:* Andy Bach > *Sent:* Tuesday, August 25, 2020 12:18 PM > *To:* Parrot Raiser <1parr...@gmail.com> > *Cc:* perl6-users ; ToddAndMargo < > toddandma...@zoho.com> > *Subject:* Re: print particular lines question > > On Win10 > C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "say > lines()[1,7,3]; " > (Line 2 Line 8 Line 4) > (Line 11 Nil Nil) > > C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "say > lines()[1,7,3].join(qq~\n~); " > Line 2 > Line 8 > Line 4 > Use of Nil in string context > in block at -e line 1 > Use of Nil in string context > in block at -e line 1 > Line 11 > > and, speaking of that off by one problem ... lines.txt does start with > "line 0" > C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my > @x = $*IN.lines(); say @x[0,1,7,3]; " > (Line 1 Line 2 Line 8 Line 4) > > a > > Andy Bach, BS, MSCMECFA > Systems Mangler > Internet: andy_b...@wiwb.uscourts.gov > Voice: (608) 261-5738, Cell: (608) 658-1890 > > "The three great problems of computer science: > compiler complexity and 'off-by-one' errors". > https://martinfowler.com/bliki/TwoHardThings.html > > -- > *From:* Parrot Raiser <1parr...@gmail.com> > *Sent:* Tuesday, August 25, 2020 11:22 AM > *To:* Andy Bach > *Cc:* perl6-users ; ToddAndMargo < > toddandma...@zoho.com> > *Subject:* Re: print particular lines question > > That will golf a little (and improve it) to: > > $ raku -e '.say for lines()[3,2,5]' lines.txt > > but you have to remember that it's zero-based. I used the first sample > file and got > Line 4 > Line 3 > Line 6 > > "The three great problems of computer science: compiler complexity and > 'off-by-one' errors". > > > On 8/25/20, Andy Bach wrote: > >> Assigning `my @x=$_.lines` puts everything into $x[0] > > > > Trying this on windows > > > > C:\> raku.exe -e "my @x = 'lines.txt'.IO.lines; say > > @x[1,7,3].join(qq~\n~); " > > Line 1 > > Line 7 > > Line 3 > > > > or > > C:\> raku.exe -e " say 'lines.txt'.IO.lines[1,7,3].join(qq~\n~); " > > Line 1 > > Line 7 > > Line 3 > > > > a > > > > Andy Bach, BS, MSCMECFA > > Systems Mangler > > Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov > > > > Voice: (608) 261-5738, Cell: (608) 658-1890 > > > > Every man has the right to an opinion but no man > > has a right to be wrong in his facts. Nor, above all, > > to persist in errors as to facts. Bernard Baruch > > > > > > From: ToddAndMargo via perl6-users > > Sent: Monday, August 24, 2020 9:35 PM > > To: perl6-users > > Subject: print particular lines question > > > > Hi All, > > > > I seems I should know how to do this, but > > I am drawing a blank. > > > > $ cat Lines.txt | raku -ne 'say $_;' > > Line 1 > > Line 2 > > Line 3 > > Line 4 > > Line 5 > > Line 6 > > Line 7 > > Line 8 > > Line 9 > > Line 10 > > Line 11 > > > > > > I want to print liens 1, 3, and 7. > > > > Assigning `my @x=$_.lines` puts everything into $x[0] > > > > > > Many thanks, > > -T > > >
Re: print particular lines question
Ah, I see, the -n reads a line and then my lines on $*IN starts with the next one C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my @x = $*IN.lines(); say @x[0,1,7,3]; " (Line 0 Line 1 Line 7 Line 3) and so $*IN is the default for lines() C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my @x = lines(); say @x[0,1,7,3]; " (Line 0 Line 1 Line 7 Line 3) This hangs, with and without the -n C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = $*IN.lines(); say @x[0,1,7,3]; " lines.txt Though: C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = lines(); say @x[0,1,7,3]; " lines.txt (Line 1 Line 2 Line 8 Line 4) Cannot do 'get' on a handle in binary mode in block at -e line 1 a Andy Bach, BS, MSCMECFA Systems Mangler Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> Voice: (608) 261-5738, Cell: (608) 658-1890 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". https://martinfowler.com/bliki/TwoHardThings.html From: Andy Bach Sent: Tuesday, August 25, 2020 12:18 PM To: Parrot Raiser <1parr...@gmail.com> Cc: perl6-users ; ToddAndMargo Subject: Re: print particular lines question On Win10 C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "say lines()[1,7,3]; " (Line 2 Line 8 Line 4) (Line 11 Nil Nil) C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "say lines()[1,7,3].join(qq~\n~); " Line 2 Line 8 Line 4 Use of Nil in string context in block at -e line 1 Use of Nil in string context in block at -e line 1 Line 11 and, speaking of that off by one problem ... lines.txt does start with "line 0" C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = $*IN.lines(); say @x[0,1,7,3]; " (Line 1 Line 2 Line 8 Line 4) a Andy Bach, BS, MSCMECFA Systems Mangler Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> Voice: (608) 261-5738, Cell: (608) 658-1890 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". https://martinfowler.com/bliki/TwoHardThings.html From: Parrot Raiser <1parr...@gmail.com> Sent: Tuesday, August 25, 2020 11:22 AM To: Andy Bach Cc: perl6-users ; ToddAndMargo Subject: Re: print particular lines question That will golf a little (and improve it) to: $ raku -e '.say for lines()[3,2,5]' lines.txt but you have to remember that it's zero-based. I used the first sample file and got Line 4 Line 3 Line 6 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". On 8/25/20, Andy Bach wrote: >> Assigning `my @x=$_.lines` puts everything into $x[0] > > Trying this on windows > > C:\> raku.exe -e "my @x = 'lines.txt'.IO.lines; say > @x[1,7,3].join(qq~\n~); " > Line 1 > Line 7 > Line 3 > > or > C:\> raku.exe -e " say 'lines.txt'.IO.lines[1,7,3].join(qq~\n~); " > Line 1 > Line 7 > Line 3 > > a > > Andy Bach, BS, MSCMECFA > Systems Mangler > Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> > Voice: (608) 261-5738, Cell: (608) 658-1890 > > Every man has the right to an opinion but no man > has a right to be wrong in his facts. Nor, above all, > to persist in errors as to facts. Bernard Baruch > > > From: ToddAndMargo via perl6-users > Sent: Monday, August 24, 2020 9:35 PM > To: perl6-users > Subject: print particular lines question > > Hi All, > > I seems I should know how to do this, but > I am drawing a blank. > > $ cat Lines.txt | raku -ne 'say $_;' > Line 1 > Line 2 > Line 3 > Line 4 > Line 5 > Line 6 > Line 7 > Line 8 > Line 9 > Line 10 > Line 11 > > > I want to print liens 1, 3, and 7. > > Assigning `my @x=$_.lines` puts everything into $x[0] > > > Many thanks, > -T >
Re: print particular lines question
On Win10 C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "say lines()[1,7,3]; " (Line 2 Line 8 Line 4) (Line 11 Nil Nil) C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "say lines()[1,7,3].join(qq~\n~); " Line 2 Line 8 Line 4 Use of Nil in string context in block at -e line 1 Use of Nil in string context in block at -e line 1 Line 11 and, speaking of that off by one problem ... lines.txt does start with "line 0" C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = $*IN.lines(); say @x[0,1,7,3]; " (Line 1 Line 2 Line 8 Line 4) a Andy Bach, BS, MSCMECFA Systems Mangler Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> Voice: (608) 261-5738, Cell: (608) 658-1890 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". https://martinfowler.com/bliki/TwoHardThings.html From: Parrot Raiser <1parr...@gmail.com> Sent: Tuesday, August 25, 2020 11:22 AM To: Andy Bach Cc: perl6-users ; ToddAndMargo Subject: Re: print particular lines question That will golf a little (and improve it) to: $ raku -e '.say for lines()[3,2,5]' lines.txt but you have to remember that it's zero-based. I used the first sample file and got Line 4 Line 3 Line 6 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". On 8/25/20, Andy Bach wrote: >> Assigning `my @x=$_.lines` puts everything into $x[0] > > Trying this on windows > > C:\> raku.exe -e "my @x = 'lines.txt'.IO.lines; say > @x[1,7,3].join(qq~\n~); " > Line 1 > Line 7 > Line 3 > > or > C:\> raku.exe -e " say 'lines.txt'.IO.lines[1,7,3].join(qq~\n~); " > Line 1 > Line 7 > Line 3 > > a > > Andy Bach, BS, MSCMECFA > Systems Mangler > Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> > Voice: (608) 261-5738, Cell: (608) 658-1890 > > Every man has the right to an opinion but no man > has a right to be wrong in his facts. Nor, above all, > to persist in errors as to facts. Bernard Baruch > > > From: ToddAndMargo via perl6-users > Sent: Monday, August 24, 2020 9:35 PM > To: perl6-users > Subject: print particular lines question > > Hi All, > > I seems I should know how to do this, but > I am drawing a blank. > > $ cat Lines.txt | raku -ne 'say $_;' > Line 1 > Line 2 > Line 3 > Line 4 > Line 5 > Line 6 > Line 7 > Line 8 > Line 9 > Line 10 > Line 11 > > > I want to print liens 1, 3, and 7. > > Assigning `my @x=$_.lines` puts everything into $x[0] > > > Many thanks, > -T >
Re: print particular lines question
That will golf a little (and improve it) to: $ raku -e '.say for lines()[3,2,5]' lines.txt but you have to remember that it's zero-based. I used the first sample file and got Line 4 Line 3 Line 6 "The three great problems of computer science: compiler complexity and 'off-by-one' errors". On 8/25/20, Andy Bach wrote: >> Assigning `my @x=$_.lines` puts everything into $x[0] > > Trying this on windows > > C:\> raku.exe -e "my @x = 'lines.txt'.IO.lines; say > @x[1,7,3].join(qq~\n~); " > Line 1 > Line 7 > Line 3 > > or > C:\> raku.exe -e " say 'lines.txt'.IO.lines[1,7,3].join(qq~\n~); " > Line 1 > Line 7 > Line 3 > > a > > Andy Bach, BS, MSCMECFA > Systems Mangler > Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> > Voice: (608) 261-5738, Cell: (608) 658-1890 > > Every man has the right to an opinion but no man > has a right to be wrong in his facts. Nor, above all, > to persist in errors as to facts. Bernard Baruch > > ________ > From: ToddAndMargo via perl6-users > Sent: Monday, August 24, 2020 9:35 PM > To: perl6-users > Subject: print particular lines question > > Hi All, > > I seems I should know how to do this, but > I am drawing a blank. > > $ cat Lines.txt | raku -ne 'say $_;' > Line 1 > Line 2 > Line 3 > Line 4 > Line 5 > Line 6 > Line 7 > Line 8 > Line 9 > Line 10 > Line 11 > > > I want to print liens 1, 3, and 7. > > Assigning `my @x=$_.lines` puts everything into $x[0] > > > Many thanks, > -T >
Re: print particular lines question
> Assigning `my @x=$_.lines` puts everything into $x[0] Trying this on windows C:\> raku.exe -e "my @x = 'lines.txt'.IO.lines; say @x[1,7,3].join(qq~\n~); " Line 1 Line 7 Line 3 or C:\> raku.exe -e " say 'lines.txt'.IO.lines[1,7,3].join(qq~\n~); " Line 1 Line 7 Line 3 a Andy Bach, BS, MSCMECFA Systems Mangler Internet: andy_b...@wiwb.uscourts.gov<mailto:andy_b...@wiwb.uscourts.gov> Voice: (608) 261-5738, Cell: (608) 658-1890 Every man has the right to an opinion but no man has a right to be wrong in his facts. Nor, above all, to persist in errors as to facts. Bernard Baruch From: ToddAndMargo via perl6-users Sent: Monday, August 24, 2020 9:35 PM To: perl6-users Subject: print particular lines question Hi All, I seems I should know how to do this, but I am drawing a blank. $ cat Lines.txt | raku -ne 'say $_;' Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 I want to print liens 1, 3, and 7. Assigning `my @x=$_.lines` puts everything into $x[0] Many thanks, -T
Re: print particular lines question
On Mon, Aug 24, 2020 at 11:08 PM ToddAndMargo via perl6-users wrote: On 2020-08-24 19:35, ToddAndMargo via perl6-users wrote: Hi All, I seems I should know how to do this, but I am drawing a blank. $ cat Lines.txt | raku -ne 'say $_;' Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 I want to print liens 1, 3, and 7. Assigning `my @x=$_.lines` puts everything into $x[0] Many thanks, -T This is what I have so far: $ cat Lines.txt Line 0 Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 $ cat Lines.txt | raku -e ' my @x=$*IN.lines; for @x[3,2,5] {say $_};' Line 3 Line 2 Line 5 is there a quicker way to get to the point? Many thanks, -T On 2020-08-24 20:24, Curt Tilmes wrote: $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' Love it! Thank you!
Re: print particular lines question
$ cat Lines.txt | raku -e '.say for lines()[3,2,5]' On Mon, Aug 24, 2020 at 11:08 PM ToddAndMargo via perl6-users wrote: > > On 2020-08-24 19:35, ToddAndMargo via perl6-users wrote: > > Hi All, > > > > I seems I should know how to do this, but > > I am drawing a blank. > > > > $ cat Lines.txt | raku -ne 'say $_;' > > Line 1 > > Line 2 > > Line 3 > > Line 4 > > Line 5 > > Line 6 > > Line 7 > > Line 8 > > Line 9 > > Line 10 > > Line 11 > > > > > > I want to print liens 1, 3, and 7. > > > > Assigning `my @x=$_.lines` puts everything into $x[0] > > > > > > Many thanks, > > -T > > This is what I have so far: > > $ cat Lines.txt > Line 0 > Line 1 > Line 2 > Line 3 > Line 4 > Line 5 > Line 6 > Line 7 > Line 8 > Line 9 > Line 10 > Line 11 > > $ cat Lines.txt | raku -e ' my @x=$*IN.lines; for @x[3,2,5] {say $_};' > Line 3 > Line 2 > Line 5 > > > is there a quicker way to get to the point? > > Many thanks, > -T
Re: print particular lines question
On 2020-08-24 19:35, ToddAndMargo via perl6-users wrote: Hi All, I seems I should know how to do this, but I am drawing a blank. $ cat Lines.txt | raku -ne 'say $_;' Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 I want to print liens 1, 3, and 7. Assigning `my @x=$_.lines` puts everything into $x[0] Many thanks, -T This is what I have so far: $ cat Lines.txt Line 0 Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 $ cat Lines.txt | raku -e ' my @x=$*IN.lines; for @x[3,2,5] {say $_};' Line 3 Line 2 Line 5 is there a quicker way to get to the point? Many thanks, -T
print particular lines question
Hi All, I seems I should know how to do this, but I am drawing a blank. $ cat Lines.txt | raku -ne 'say $_;' Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 I want to print liens 1, 3, and 7. Assigning `my @x=$_.lines` puts everything into $x[0] Many thanks, -T