🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log inspection is getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
moon-child m: sub g($label) { last $label }; sub f { LOOP: for ^5 { say $_; g LOOP }; }; f() 00:19
camelia 0
moon-child I want to write something like ^, but with map instead of for. Is that possible? 00:20
Geth ecosystem: 26698f7b77 | (Juan Julián Merelo Guervós)++ (committed using GitHub Web editor) | META.list
Freeze Test::When
08:42
Geth ecosystem: 330333dd65 | (Juan Julián Merelo Guervós)++ (committed using GitHub Web editor) | META.list
Freeze IO::Dir
09:15
Voldenet m: sub g($lbl is rw) { $lbl = True }; my $*LOOP = False; say reduce( -> $acc, $_ { my $v = $*LOOP ?? ($acc) !! (|$acc, $_); g($*LOOP); $v }, (), |^5); 12:37
camelia (0)
Voldenet moon-child: ^ that's not map, but it's close to how fprog would solve this (I'm not sure if it's even always guaranteed to work) 12:39
m: sub g($states, $key) { $states{$key} = False }; say reduce( -> (%d, $acc), $_ { my $v = %d<LOOP> ?? (|$acc, $_) !! ($acc); g(%d, <LOOP>); say (%d, $acc, $_); (%d,$v) }, (%(:LOOP), ()), |^5); 12:48
camelia ({LOOP => False} () 0)
({LOOP => False} (0) 1)
({LOOP => False} (0) 2)
({LOOP => False} (0) 3)
({LOOP => False} (0) 4)
({LOOP => False} (0))
Voldenet output is fairly disgusting as expected
Voldenet in fact, for loop seems like a better solution for this 12:58
[Coke] say:print::note:? 14:59
$*ERR.print? 15:00
japhb [Coke]: note ~? (Stringifying the argument first) 15:50
[Coke] Was referring to newline addition. 16:20
but yes, having gist vs. str in the mix is also confusing. 16:21
japhb Oh yeah, I guess I was thinking say:put 16:25
aru Hi, i've been looking at raku and ocasionally I'm confused by its syntax and where ceratin things can be used. For example with grep, I'm never sure if I have to do grep({ .something }), or grep(*.something), or grep: { .something } or something else altogether. Is there a rule of thumb for these cases? 17:39
lizmat the rule is that .grep takes a Callable 17:40
{ .something } and *.something are different syntaxes for basically the same tihng
aru are they? I could have sworn there were cases when one worked and the other did not, but maybe I was doing something else wrong 17:41
lizmat also .grep({ ... }) and .grep: { ... } are also just different syntaxes for the same tinkg
well, *.foo is syntactic sugar.... and the syntax to convert an expression with * into a Callable are (intentionally) limited 17:42
aru ok, makes sense, thanks 17:45
and another thing, when it comes to specifying types. Can I express something like "a list of lists of Str*Int pairs"? 17:46
gfldex Type checks happen (mostly) at runtime and you can check for anything you like. 17:53
aru right 18:01
Voldenet aru: this is mostly my personal opinion, but I really prefer the most uniform syntax in raku, so `.grep({ $^x })` which can be used almost everywhere 18:43
`.grep: { }` feels weird to use 18:45
`*.something` is convenient when you chain a lot of methods together 18:49
like `($^d.IO.dir // ()).grep(!*.basename.starts-with('.')).grep(*.d).grep(!*.l)` 18:53
also, WhateverStar has some limitations: 19:00
m: (&say, &dd).map(*("test")).say
camelia No such method 'CALL-ME' for invocant of type 'Whatever'
in block <unit> at <tmp> line 1
Voldenet m: (&say, &dd).map({.("test")}).say
camelia test
"test"
(True Nil)
japhb m: (&say, &dd).map: *.("test") # Curious 19:08
camelia No such method 'CALL-ME' for invocant of type 'Whatever'
in block <unit> at <tmp> line 1
japhb Yeah, figured
aru understood, thanks 19:22