This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
Nemokosch my %foo = BaR => 42, lol => 31; say 'bar' ∈ %foo.keys>>.lc; 00:03
deoac Oh, a very nice solution.  Thank you. 00:08
Nemokosch 😺 00:11
00:12 Kaiepi left 00:39 sgrs left 02:10 razetime joined 02:43 razetime left
gfldex_ m: my %h = :1BaRr, :2foo; my &f = { say 'f' }; say %h.first(rx:i /bar/ ).so; 03:58
camelia True
03:59 Kaiepi joined
gfldex_ m: my %h = :1BaRr, :2foo; my &f = { say 'f' }; say so %h ~~ rx:i/bar/; 04:02
camelia True
gfldex_ deoac: This ^^^ is the ideomatic way. Map.ACCEPTS takes a regex. 04:03
SmokeMachine deoac: have you thought on doing something like this? 04:37
04:42 Heptite left
deoac gfldex_: Thanks, that's surprisingly easy! 05:14
SmokeMachine: I'm going to download and study that code.  I think I could learn a lot from it.  Thank you. 05:15
Mason can someone please explain what is going on here? 07:16
`.trans('a'..'z' => 1..26, 'A'..'Z' => 27..52)`
specifically the fat arrow syntax with ranges in it
is it making a list of pairs with ranges in them?
are there other ways to use this data structure?
(e.g. instead of a string if I have a list of numbers, is there a `trans` like function I could call on the list?) 07:17
07:44 deoac left 08:05 razetime joined
p6steve gfldex: very nice ... could also use as a jump start 08:14
smokemachine: very nice ... could also use as a jump start 08:15
Kaiepi <@259818303420235786> it's passing two pairs with ranges as keys and values as arguments to `trans` 08:17
08:19 ToddAndMargo joined
ToddAndMargo NativeCall question:  I have 4 bytes in a CArray representing a little ending c pointer.  How do I assign those byes to a Pointer? 08:21
sorry, that was 8 bytes
p6steve m: say 'yo' 08:23
(just checking that m: robot works in Discord) 08:24
ToddAndMargo yo
p6steve m: "aaa1123bb123c".trans('a'..'z' => 'A'..'Z').say
<@259818303420235786> not sure what is the Str you are applying .trans method to ... if you just have one Pair as arg, then the Str is translated one char at a time and the matching key becomes that value 08:25
<@259818303420235786> since you are passing two Pairs, .trans is confused and only applies the first one 08:28
m: "aaa1123bb123c".trans('a'..'z' => 'A'..'Z').say;
Mason it works fine actually with two pairs
p6steve m:"aaa1123bb123c".trans('a'..'z' => 1..26, 'A'..'Z' => 27..52).say;
Mason and is an example I pulled out of the docs 08:29
p6steve m: "aaa1123bb123c".trans('a'..'z' => 1..26, 'A'..'Z' => 27..52).say;
<@259818303420235786> ah - my bad ... 08:30
Mason m: 'QLFdFCdlLcVqdvFLnFLSSShZwptfHHhfZZZpSwfmHp'.trans('a'..'z' => 1.chr..26.chr, 'A'..'Z' => 27.chr..52.chr).ords
is an example of what I am currently doing
m: 'QLFdFCdlLcVqdvFLnFLSSShZwptfHHhfZZZpSwfmHp'.trans('a'..'z' => 1.chr..26.chr, 'A'..'Z' => 27.chr..52.chr).ords.say;
I'd love a way to do something like `*.ords.trans('a'.ord..'z'.ord => 1..26, 'A'.ord..'Z'.ord => 27..52)` instead (or, like, without the inner ord and the ords call) but what I currently have works 08:32
p6steve m: 'QLFdFCdlLcVqdvFLnFLSSShZwptfHHhfZZZpSwfmHp'..ords.trans('a'.ord..'z'.ord => 1..26, 'A'.ord..'Z'.ord => 27..52).say; 08:37
m: 'QLFdFCdlLcVqdvFLnFLSSShZwptfHHhfZZZpSwfmHp'.ords.trans('a'.ord..'z'.ord => 1..26, 'A'.ord..'Z'.ord => 27..52).say; 08:38
works for me :-)
[probably I misunderstand what you are aiming for] 08:39
Kaiepi SmokeMachine, if you're making an Associative, i'd make it Iterable and err against proxying when possible 08:40
begh, Iterable has a bit fair bit of API that need handling. there are some extra handles that would help to have regardless 08:46
p6steve fwiw it is a mystery to me how the Pair of Ranges works ... 08:51
... the docs say *In this case, neither origin nor target in the Pair are Str; the method with the Pair signature then calls the second, making this call above equivalent to "abcd".trans: ["a"] => ["zz"], (with the comma behind, making it a Positional, instead of a Pair), resulting in the behavior shown as output.* ... 08:52
... but that serves to deepen the mystery for me (the docs I read are
Mason oh, I guess it does work, but it's a massive performance penalty 08:53
I'm doing like *checks notes* 3 thousand of these strings
I'm doing like *checks notes* 3000 of these strings
doing it the ord way is like a couple seconds, doing it the chr way is like a tenth of a second 08:54
I assume because all the numbers then have to be parsed as strings again
hmm, my new methodology that uses bags instead of products makes that penalty only about 3x slower 08:59
instead of like x40 it was before
p6steve maybe you can keep the numbers as Str like 'A'.ord..'Z'.ord => '27'..'52' ?
Mason I have to actually interpret them as numbers later on
p6steve m: '27'.Int.say 09:00
could save the conversion for later
Mason that's the problem
my math routines take 4 seconds if I do it this way 09:01
they take 0.1 the other way
p6steve m: +'27'.^name
Mason every pre-emptively converting them, they still take 0.36 seconds instead of 0.12
it's fine, you are right it works, I misremembered, but the performance costs are a lot 09:02
p6steve m: +'27'.^name;
Mason m: (+'27').^name; 09:03
p6steve tx!
must afk for now
Mason m: (+'27').^name.say;
yea I am deeply confused about what is happening here, would be cool to use it for other things is why I am interested 09:04
SmokeMachine Kaiepi: thanks! I had forgotten about those *-KEY methods. 09:56
10:31 sgrs joined 10:41 razetime left 10:43 human-blip joined 10:48 razetime joined
Nemokosch Hello 11:04
11:09 sgrs left 11:20 Kaiepi left
I have to say, the documentation of trans is tragic 11:22
I'm afraid the design of the method also is
p6steve m: dd 'mykey=myval'.split('=').Hash.first 11:40
m: dd 'mykey=myval'.split('=').Pair
wonders if there is a single method or other, better idiom to make a .Seq of two things into a Pair 11:41
Nemokosch .pairup? 11:43
m: dd 'mykey=myval'.split('=').pairup
idk if this is a better way though because you'd still need to call .first 11:45
11:46 human-blip left
re %h ~~ rx:i/bar/ - here, Regex.ACCEPTS takes a Map but apparently this particular case is commutative, interestingly 11:53
<@259818303420235786> anyway, trans in particular is only for strings 11:54
I'm not aware of an analogous method for stuff that shouldn't be interpreted as strings 11:55
You could write a map
m: 'QLFdFCdlLcVqdvFLnFLSSShZwptfHHhfZZZpSwfmHp'{ when 'a'.ord..'z'.ord { $_ - 'a'.ord + 1 }; when 'A'.ord..'Z'.ord { $_ - 'A'.ord + 27 }; $_ }).say; 12:03
if that was your primary interest: no, a Pair of Ranges isn't a "smart" data structure; all magic was done by trans itself - mainly to mimic the Unix `tr` command 12:05
maybe it's a good idea to generate a Map from the mappings 😛 12:09
13:48 Kaiepi joined 13:50 gfldex_ is now known as gfldex 15:24 Heptite joined 15:55 deoac joined 16:35 razetime left
p6steve m: say my Pair $p .= new( |'mykey=myval'.split('=') ); 16:39
^ that is maybe more natural than .Hash.first ... 16:41
^ note the '|' to slip in the Seq
Nemokosch not a big fan of this .= new(...) paradigm 16:42
p6steve odd, because it's one of my favourites 17:05
you could just write my Thing $t = every time
if you like typing
and writing things twice
Nemokosch I usually don't use type annotations 17:09
and I particularly don't like to use the constructor for something as banal as a Pair 17:10
p6steve I agree, but I prefer to Hash.first when I am working with a pair from a config string like 'key=value' since it has lower wattage 17:14
well I use code in general (and raku in particular) to whip up ideas quickly and then, as it gets unmanageable, to chunk into pieces and then assemble them ... as I do this, the structure emerges and I like to use OO to "describe" the pieces --- later on, while I was initially resistant, I have grown to like class types as a way to convey this information ... but ymmv ;-) 17:18
Nemokosch what does ymmv stand for? 😄 17:21
p6steve 17:41
Nemokosch <:cameliathink:897316667653247057> 18:27
18:53 Kaiepi left 18:54 Kaiepi joined
deoac m:     say gather for (:x<a b>, :y<a b>) -> $p {take (|$p.invert)}; 19:42
camelia (a => x b => x a => y b => y)
deoac     say gather for (:x<a b>, :y<a b>) -> $p {take |$p.invert};
m:    say gather for (:x<a b>, :y<a b>) -> $p {take |$p.invert};
camelia ((a => x b => x) (a => y b => y))
deoac Why are the outputs of the two statements different?  Why do the parens around |$p.invert matter?
Nemokosch you know what | does, right? 19:48
oh, perhaps I'm not even asking the most important question 19:49
do you know that `f x` and `f (x)` are not the same in Raku in general?
deoac Ah, I'm passing different things to `take` in each case.  Got it. Thanks. 19:56
Nemokosch yep, the space makes a difference here between f(x) and f (x)
20:14 Heptite left