🦋 Welcome to the former MAIN() IRC channel of the Raku Programming Language (raku.org). This channel has moved to Libera (irc.libera.chat #raku)
Set by lizmat on 23 May 2021.
jdv if someone is doing something funky with their .raku then its likely on them 00:24
that's what .gist is for iirc
the 2 have distinct purposes, right?
guifa jdv: .gist = human readable, .raku = recreate raku object, .put = computer readable 00:37
err 00:38
.gist = human readable (used by say), .raku = recreate raku object, .Str = computer readable (used by put and print)
codesections But in many cases, the .raku doesn't recreate the raku object, and there's no real path getting it to (other than implementing it manually) 01:11
m: | ~''
camelia ( no output )
codesections m: my class Foo { has $!bar; submethod BUILD(:$!bar) {}}; say Foo.new(:bar<baz>) eqv Foo.new(:bar<qux>)
camelia True
guifa codesections: I think that goes back to the private attributes being like implementatino details 01:47
avuserow if I have a hash with an key that is either a list or not present in the hash, is there an easy way to iterate over it with a for loop? for example: 03:19
m: my %a = :a[1, 2, 3]; .say for %a<a>; .say for %a<b> # wrong
camelia [1 2 3]
(Any)
avuserow m: my %a = :a[1, 2, 3]; .say for @(%a<a> // []); .say for @(%a<b> // []) # best I've found so far
camelia 1
2
3
avuserow fwiw, in python I would write `for x in a.get("a", []): print(x)` 03:22
raydiak not sure if this is better for your use case, but you could also do: 03:31
m: my %a is default([]) = :a[1, 2, 3]; .say for |%a<a>; .say for |%a<b>
camelia 1
2
3
avuserow oh nice, I was wondering if we had a defaultdict equivalent somewhere 03:35
that definitely helps some of the time 03:36
usually when this frustrates me, I'm delving into data that came from json, so that's not an option unfortunately
raydiak ah, I could see that 03:37
avuserow m: my %a = :a[1, 2, 3]; .say for %a<a> andthen .list; .say for %a<b> andthen .list # also works, not sure if it's an improvement 03:49
camelia 1
2
3
raydiak oh, here's a neat trick I hadn't thought of before now... 03:52
m: my %a = :a[1, 2, 3]; .say for %a<a>:v; .say for %a<b>:v
camelia 1
2
3
avuserow raydiak++ nice 04:06
MrFantastik junctions are cool 17:18
guifa my $junctions = 'cool' & 'awesome' & 'fun'; 17:39
codesections .tell avuserow the most direct Raku translation of `for x in a.get("a", []): print(x)` is probably `for %a.keys { say %a{$_}}` 20:21
tellable6 codesections, I'll pass your message to avuserow
dcx Hey is there any way to stop interactive raku from closing when I press ^C? 21:02
Like in many languages that just stops the main thread and gets you a new line but here it causes the raku interpreter to close 21:03
In python I think it raises a keyboard exception I think
MasterDuke34 i suspect the repl could start with a signal handler for ^C. probably worth raising an issue on github asking about it 21:07
leont control-C raises a SIGINT
You can handle that, but making it throw an exception right there and then is trickier 21:08
dcx Ok I'll open an issue :) 21:09
This is an issue for rakudo right?
kybr i'm trying to get the behaviour of the command line `sort -df` from our .sort operation. it is sortof .sort({$^a.uc cmp $^b.uc}) but that does not ignore all chars except letters and spaces. 21:10
codesections leont: what's tricky about throwing there? I would have thought that `signal(SIGINT).tap({die})` would work -- am I missing something? 21:11
kybr i guess i have to regex
leont When will that throw? And whereto? 21:12
It's handled by the event loop, I can only assume it will be handled as other asynchronous IO 21:13
dcx Opened 21:22
codesections m: <Nab Not word!z word@a other next>.sort: {S/\W//.&fc} 21:36
camelia ( no output )
codesections m: say <Nab Not word!z word@a other next>.sort: {S/\W//.&fc}
camelia (Nab next Not other word@a word!z)
codesections kybr: I'd probably do ^^^ (not sure if you'd count that as using a regex or not) 21:37