This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
00:25 Chanakan joined 02:47 teatime joined
rcmlz m: grammar Splitter { # as many times as possible size $m, then sizes $n, until entire string is consumed token TOP ( $m, $n ) { [:!r <long>+] <short>+ } # no ratchet for <long>, needs to look backwards to make <short> match token long { \w {$*m} } token short { \w {$*n} } } my @tests = [ ['thisisfun', 3, 3, <thi sis fun>, 'three times 05:06
len 3'], ['thisisfunxx', 3, 2, <thi sis fun xx>, 'three times len 3, one time len 2'], ['ifmanwasmeanttostayonthegroundgodwouldhavegivenusroots', 7, 6, <ifmanwa smeantt ostayon thegrou ndgodwo uldhave givenu sroots>, 'six times len 7, two times len 6'], ]; use Test; for @tests -> ($in, $m, $n, $res, $desc) { my $parsed = Splitter.parse($in, :args(($m,$n))).hash; my @matches = map *.Str,
|$parsed{'long'}, |$parsed{'short'}; is @matches, $res, $desc }
Raku eval ok 1 - three times len 3 ok 2 - three times len 3, one time len 2 ok 3 - six times len 7, two times len 6
rcmlz but better looked at here: gist.github.com/rcmlz/189df1e4386c...9b9ed242e5 05:07
so the solution was to turn „ratchet“ off for the first token. 05:08
and pass two parameter to the grammar. 05:09
05:34 teatime left 05:47 teatime joined
ab5tract Cheers, thanks! 07:09
11:37 lizmat_ joined 11:41 lizmat left 11:42 lizmat_ left, lizmat joined 12:59 avuserow_ left 13:00 MasterDuke joined, avuserow_ joined 13:42 jgaz joined 14:06 teatime left 14:07 teatime joined
jgaz I know I can put `state $i = 0;` ... `$i++;` in a for loop, but isn't there a Raku magic variable that keeps track of the loop count? For context: I'm keeping track of my line number given a multi-line string. 16:03
lizmat m: for ^10 { say $_ } 16:11
camelia 0
1
2
3
4
5
6
7
8
9
lizmat m: sub a() { say $++ }; a for ^10 16:12
camelia 0
1
2
3
4
5
6
7
8
9
lizmat $ being the nameless state variable
jgaz interesting 16:17
thanks
nahita3882 you can also .kv the iteratee and have the parametrized block as, e.g., -> $idx, $val 17:15
i'm 96% sure iteratee isn't a word but what I meant is the thing you are iterating over like for @things.kv -> $idx, $val { ... }
oh wow it's a word en.wikipedia.org/wiki/Iteratee but means something else i guess 17:17
23:13 kjp left