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.
el gatito (** advocate) m: say 'she sells seashells by the seashore'.comb.filter({$_ ~~ rx:i/s/}) 00:43
Raku eval Exit code: 1 No such method 'filter' for invocant of type 'Seq' in block <unit> at main.raku line 1
el gatito (** advocate) what 00:44
Nemokosch filter, lol
tenor.com/view/heresy-detected-gif-25567321
el gatito (** advocate) m: say ($_ if $_ ~~ rx:i/s/ for 'she sells seashells by the seashore'.comb).join
Raku eval ssssssss
el gatito (** advocate) comprehension yay 00:45
m: say ($_ if $_ !~~ rx:i/s/ for 'she sells seashells by the seashore'.comb).join
Raku eval he ell eahell by the eahore
Nemokosch m: say ($_ if m:i/s/ for 'she sells seashells by the seashore'.comb).join
Raku eval ssssssss
el gatito (** advocate) m: say ($_ if $_ != 's' for 'she sells seashells by the seashore'.comb).join 00:46
Raku eval Exit code: 1 Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏s' (indicated by ⏏) in block <unit> at main.raku line 1
el gatito (** advocate) oof
m: say ($_ if $_ ne 's' for 'she sells seashells by the seashore'.comb).join
Raku eval he ell eahell by the eahore
Nemokosch I saw this with the new colleague as well, the other way around
... eq 2
but that would work basically, haha 00:47
el gatito (** advocate) non generic == and + always gets me
Nemokosch well + is a bit bizarre if you think about it 00:48
it's not commutative
el gatito (** advocate) m:i/s/ == rx:i/s/.match($_)?
how? 😭 00:50
Nemokosch have you never used unix? 😂 00:51
I think so
el gatito (** advocate) grep? i used linux mint but i never felt the need to grep 00:52
Nemokosch grep
which stands for g/re/p iirc 00:53
a sed command
execute a Global command: if the Regular Expression matches, Print the line 00:54
el gatito (** advocate) m: say $_ for 'she sells seashells by the seashore'.grep(rx:i/<-[s]>/) 01:01
Raku eval she sells seashells by the seashore
el gatito (** advocate) what
m: say $_ for 'she sells seashells by the seashore'.comb.grep(rx:i/<-[s]>/) 01:02
Raku eval h e e l l e a h e l l b y t h e e a h o r e
el gatito (** advocate) lmao
Nemokosch because of the say for all iterations 01:10
01:18 Manifest0 left
el gatito (** advocate) when will raku have discord formatting tbh 01:39
02:55 rf left 03:15 jgaz left 04:32 deoac joined
elcaro If you wanted to remove all 's' from the string (ie. without combing), then .subst is the way to go > 'she sells seashells by the seashore'.subst(/s/, '', :g) he ell eahell by the eahore 04:58
On a similar note... many years ago, prior to the christmas release, I advocated for an alternate name for grep. At the time, I suggested where , as it's - in some ways - similar to a sunset clause. I still don't love grep for a name, despite being very familiar with linux. If I had my way, I'd call it keep, and have an inverse method called drop. Reason being is that grepping for a positive match is easy 05:06
$str.words.grep(/sea/) @items.grep(&some-boolean-func) but to do the inverse, you need to use a block $str.words.grep({ !/sea/ }) @items.grep(-> $x { !some-boolean-func($x) })
05:15 deoac left 05:21 shmup joined 05:26 Heptite left
I guess you can also do .grep(!*.&func)... now we're up to 4 symbols in a row. 05:27
el gatito (** advocate) select/filter and remove 05:36
elcaro One of the benefits of grep is it's nice and short. keep and drop are the same amount of characters. While I'm at it, I'd rename reduce and produce to fold and scan... 4 letter methods for everybody! 05:52
except you, map
Ruby has an each method that's kind of like map but it mutates the args. 05:54
I think. I don't use Ruby.
el gatito (** advocate) it also have map 08:08
why 😭 08:10
elcaro I already use perl, python, and raku. Ruby looks like a nice enough language, but I feel learning wouldn't really add much to my toolbelt 08:14
el gatito (** advocate) it has a radical OOP model based on smalltalk which might be enough of a difference to you 08:17
Nemokosch Smalltalk seems ugly 08:22
el gatito (** advocate) yes which is why ruby exists (i think) 08:23
Nahita > but to do the inverse, you need to use a block there's none perl >>> my @vals = ["seat", "Sean", "other"] [seat Sean other] >>> @vals.grep(/ <[sS]>ea /) (seat Sean) >>> @vals.grep(none / <[sS]>ea /) (other) >>> my &cond = *.chars == 4 WhateverCode.new >>> @vals.grep(&cond) (seat Sean) >>> @vals.grep(none &cond) (other) 08:27
Nemokosch Hmmm 08:29
el gatito (** advocate) can i use ~ instead of none
Nahita that's stringifier no
el gatito (** advocate) how about !
i think no 08:30
Nahita it acts immediately so no
el gatito (** advocate) me when 08:31
no symbol for none junction 08:32
but then raku has too much symbols so a blessing ig
Nemokosch The thing to realize here is that none acts like a higher order thing, something that can compose matchers 08:33
And functions are matchers
el gatito (** advocate) so are & and |
Nemokosch Absolutely
"If none of (this one thing)" smartmatches 08:36
Quite a creative usage
elcaro Ideally, filtering a positive match and a negative match should have similar performance characteristics. Last time I checked, junctions incurred quite a perf hit. Admittedly, it's been a while since I benched it, and I know some work was put in to speed up evaluating junctions when only a boolean was needed 08:48
el gatito (** advocate) m: sub generator() { gather { take 1; take 2; take 3; } } my $gen := generator; .say for $gen; 08:50
Nemokosch Yep... in theory, it's a smartmatch on a function, in practice, it's inlined probably
Raku eval 1 2 3
el gatito (** advocate) m: sub generator() { gather { take 1; take 2; take 3; } } my $gen := generator; say $gen; .say for $gen; 08:51
Raku eval (1 2 3) 1 2 3
08:51 human-blip left
el gatito (** advocate) m: sub fib() { gather { my $res := 0; my $next := 1; yield $res; my ($res, $next) := ($next, $res + $next); } } my $gen := fib; say $gen; 08:55
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Redeclaration of symbol '$res'. at /home/glot/main.raku:6 ------> my ($res⏏, $next) := ($next, $res + $next); expecting any of: shape declaration
el gatito (** advocate) m: sub fib() { gather { my $res := 0; my $next := 1; take $res; ($res, $next) := ($next, $res + $next); } } my $gen := fib; say $gen; 08:56
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Cannot use bind operator with this left-hand side at /home/glot/main.raku:6 ------> ($res, $next) := ($next, $res + $next)⏏;
el gatito (** advocate) why can’t
m: sub fib() { gather { my $res = 0; my $next = 1; take $res; ($res, $next) = ($next, $res + $next); } } my $gen = fib; say $gen; 08:57
Raku eval (0)
08:58 Manifest0 joined
el gatito (** advocate) m: sub fib() { gather { my $res = 0; my $next = 1; loop { take $res; ($res, $next) = ($next, $res + $next); } } } my $gen = fib; say $gen; 08:58
Raku eval (0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 4807526976 7778742049 12586269025 20365011074 32951280099 53316291173 86267571272 139583862445 225851433717
365435296162 591286729879 956722026041 1548008755920 2504730781961 4052739537881 6557470319842 10610209857723 17167680177565 27777890035288 44945570212853 72723460248141 117669030460994 190392490709135 308061521170129 498454011879264 806515533049393 1304969544928657 2111485077978050 3416454622906707 5527939700884757 8944394323791464 14472334024676221 23416728348467685 37889062373143906 61305790721611591
99194853094755497 160500643816367088 259695496911122585 420196140727489673 679891637638612258 1100087778366101931 1779979416004714189 2880067194370816120 4660046610375530309 7540113804746346429 12200160415121876738 19740274219868223167 31940434634990099905 51680708854858323072 83621143489848422977 135301852344706746049 218922995834555169026 ...)
el gatito (** advocate) tf
is gather..take a lazy sequence or smth 08:59
also take is a terrible name 09:01
Nemokosch it kind of is but this output wouldn't tell you that
el gatito (** advocate) should be yield or give 09:03
m: sub fib() { gather { my $res = 0; my $next = 1; loop { take $res; ($res, $next) = ($next, $res + $next); } } } my $gen = fib; say $gen.WHAT; 09:04
Raku eval (Seq)
el gatito (** advocate) yeah a lazy Seq interesting how it is not its own type 09:05
why can’t i “destructure bind”?
09:08 dakkar joined
Nemokosch no idea 09:12
09:37 ab5tract joined
el gatito (** advocate) probably one of the nyi features 09:54
Nemokosch 👀 09:57
el gatito (** advocate) uh nothing 09:58
ill create a github issue abt that lmao
Nemokosch 😂 10:04
m: sub fib() { gather { my $res = 0; my $next = 1; loop { take $res; :($res, $next) = ($next, $res + $next); # test } } } my $gen = fib; say $gen.WHAT; 10:06
Raku eval (Seq)
Nemokosch oops dumb
see #bot-testing 10:07
it works with binding :cameliathink:
el gatito (** advocate) yay i created the issue 10:31
hmm 10:32
13:14 Heptite joined 13:49 deoac joined 14:34 ab5tract left 16:03 deoac left 16:57 n1to joined 17:13 n1to left 17:31 saint- joined 17:37 dakkar left 18:48 ab5tract joined 19:17 deoac joined 22:21 deoac left