01:02 kjp left 01:03 kjp joined 01:04 kjp left 01:05 kjp joined 01:35 CultOfTheGlenda joined
CultOfTheGlenda Good morning. I probably have another stupid question. I want to add some sort of operator or language construct. It will look something like 01:39
do-when $t {
  #some callable here
}
In this case $t is a DateTime. I can achieve what I want by using a subroutine or prefix operator for the most part but I have to use a comma after the $t. Essentially I want that gone.
I think I've read that things like for loops are written in raku in an operator or grammar. That is basically what I am looking to do. If someone could point me to that, that would be great. Just trying to learn more of the deeper innerworkings. Thanks guys. 01:46
Voldenet I think there is such operator already 01:50
m: my $x = DateTime.now; with $x { .say }; # defined 01:51
camelia 2025-09-25T03:51:25.061270+02:00
Voldenet m: my DateTime $x;; with $x { .say }; # not defined
camelia ( no output )
Voldenet s/operator/keyword/
there are plenty of ways to do exactly what you want or something similar - the easiest (but not precisely what you want) is a sub 01:53
m: sub do-when ($y, &x) { with $y { x($y) } }; do-when DateTime.now, { .say } # no hacking, boring code
camelia 2025-09-25T03:54:00.063156+02:00 01:54
Voldenet it requires `,` after the parameter, so it's not as good
CultOfTheGlenda Yeah, this is an exercise to learn more about raku(do). What's the hard way? 01:56
Voldenet other option is a slang (where you add subrules to a grammar) - it's sufficiently complex at the moment because of QAST/RakuAST differences 01:57
github.com/0racle/raku-Slang-Other...ree/master example slang, but you can find more in raku.lang
raku.land* 01:58
CultOfTheGlenda Thanks, I was afraid slang was the way. That comma is looking better already. 01:59
Voldenet I think the most modern way would be rakuast macros
there's also keywords on the HOW levels, but I think they're limited to defining class-like keywords, maybe I'm not seeing bigger picture though 02:00
example of that approach (probably not applicable to defining entirely new syntax) github.com/raku-community-modules/.../tree/main 02:01
CultOfTheGlenda One thing that confuses me about raku is arrays in a hashmap. I will then point another array at that nested array thusly
my @ss := %hashmap<key-that-points-to-array>;
When I do that @ss becomes a nested array. Why is that?
I've been doing raku for years now, and that still trips me up. 02:02
Voldenet m: my %x = a => [1]; say %x<a>; my @n := %x<a>; say @n 02:03
camelia [1]
[1]
Voldenet you mean the above?
m: my %x = a => [1]; say %x<a>; my @n := %x<a>; say @n; my @nested = %x<a>; 02:04
camelia [1]
[1]
Voldenet m: my %x = a => [1]; say %x<a>; my @n := %x<a>; say @n; my @nested = %x<a>; say @nested
camelia [1]
[1]
[[1]]
Voldenet the last one copies the scalar that contains an array 02:07
you can see incarnations of this in many places 02:08
m: my %x = a => [1, 2, 3]; for %x<a> { .say }
camelia [1 2 3]
.landyacht. m: my %x = a => [1, 2, 3]; for @%x<a> { .say } 02:09
evalable6 (exit code 1) Type List does not support associative indexing.
in block <unit> at /tmp/Szu2Abr8kU line 1
.landyacht. ay?
m: my %x = a => [1, 2, 3]; for @(%x<a>) { .say }
evalable6 1
2
3
Voldenet The above is what I used to do, but
.landyacht. eesh, don't love that...
Voldenet it's not quite right
it calls .list on that and COPIES the contents
but what you can do is say "I don't want the container but the contents" 02:10
m: my %x = a => [1, 2, 3]; for %x<a><> { .say }
camelia 1
2
3
.landyacht. I'm sure I remember this working this way to make something else DWIM nicely, but I can't for the life of me remember what that thing is
Voldenet m: my %x = a => [1, 2, 3]; for %x<a>.list { .say } # this is doing the same as @(…) version 02:13
camelia 1
2
3
Voldenet lists aren't expensive, but at the moment I think they're allocated, so they're not as free as the version with <> 02:16
there's also Slip version of it, but I don't know how that internally works 02:24
m: my %x = a => [1, 2, 3]; for |%x<a> { .say } # the same as %x<a>.Slip 02:25
camelia 1
2
3
Voldenet Slip also probably copies the list, that's what benchmarks suggest at the moment: 0x0.st/KmV7.raku 02:36
02:43 greaser|q left, greaser|q joined, greaser|q is now known as GreaseMonkey
cultoftheglenda Back on discord. Thanks for all the information guys. 03:26
CultOfTheGlenda What would the performance impact be of a shlang? 03:59
04:07 CultOfTheGlenda left
Voldenet CultOfTheGlenda: altering the grammar takes up to 1s, but after that there's hardly any impact 04:11
tellable6 Voldenet, I'll pass your message to CultOfTheGlenda
04:34 derpydoo joined 05:24 Aedil joined, derpydoo left 05:34 Sgeo left 05:50 melezhik joined 06:06 abraxxa joined 06:31 derpydoo joined 07:20 melezhik_ joined
melezhik_ .tell ds7832: - please take a look at Sparky - looks good for your tasks IMHO - gist.github.com/melezhik/d1f42e5ef...ef5da5b879 07:27
tellable6 melezhik_, I'll pass your message to ds7832
07:27 melezhik_ left