This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
01:40 habere-et-disper left 01:46 ToddAndMargo joined 02:10 razetime joined 02:13 human-blip left 02:25 ToddAndMargo left 02:38 razetime left 02:46 razetime joined 03:09 Kaiepi left 03:56 jaguart joined
jaguart it is possible to declare a named my $var in trailing for-range iteration? 04:02
m: say "am $_" for 1..2
camelia am 1
am 2
jaguart m: say "am $item" for 1..2 -> $item 04:03
camelia ===SORRY!=== Error while compiling <tmp>
Variable '$item' is not declared. Did you mean '&item'?
at <tmp>:1
------> say "am โ$item" for 1..2 -> $item
Mason so, is there a way to do this? 05:51
my @example = [
['A', 'X'],
sub test($a, $x) {
say "{$a}-{$x}";
}; #what do I do here?
I know I can change the signature of test to `sub test(($a, $x)) { ` and it works, but how do I call the function without modifying it?
so, is there a way to do this?
my @example = [
['A', 'X'],
sub test($a, $x) {
say "{$a}-{$x}";
}; #what do I do here?
I know I can change the signature of test to `sub test(($a, $x)) { ` and it works, but how do I call the function in map without modifying it? Do I have to expand it fully?
07:25 fishtank joined 07:29 fishtank left
Nemokosch jaguart: no, it's not possible 08:40
jaguart Are there any Raku bindings for R - the math/stats libraries, like Perl s Math::GammaFunction? 08:44
Nemokosch <@259818303420235786> (Mason for IRC folks) if you are confident they all contain two elements, you could flatten it all ๐Ÿ˜„ 08:47
By the way, is there a reason you are putting them into arrays or is that just a habit from other languages? 08:48
Mason habit from other languages probably, was just trying to get the example loaded, no clue what they actually are in what I was working with 08:49
Nemokosch ['A', 'X'] looks like you're gonna mutate the individual letters 08:50
Mason Ah, makes sense 08:52
FWIW this it in context:
should probably change those arrays to lists 08:53
Nemokosch There is another thing I'm not sure you'd want to know right now 08:55
But I'm gonna say it anyway, lest it surprise you later
There are in fact two assignments that look the same but have different implementation and different precedence even 08:56
so my ```perl 08:58
@example = [
['A', 'X'],
does the same thing as
```perl 08:59
@example = (
['A', 'X'],
or even
@example =
['A', 'X'],
['A', 'X'],
['A', 'X'];
(I hope the newlines are allowed here, that I haven't checked)
jaguart m: say [<a b c>].^name 09:00
camelia Array
jaguart m: say (<a b c>).^name 09:01
camelia List
jaguart kind of expected though?
Nemokosch what you sent is expected - but it might not be expected that @example is gonna be the very same Array, no matter which of these you assign to it 09:02
m: say (@ = (<a b c>)).^name 09:03
oh by the way, (<a b c>) is not a nested List, it's just ('a', 'b', 'c') 09:04
while [<a b c>] is a one-element Array containing the List ('a', 'b', 'c') 09:05
jaguart m: say [<a b c>].elems
camelia 3
Nemokosch <@259818303420235786> I don't know if you have heard this already but Lists are created by the comma operator, not the parens (except for the empty List)
jaguart yeah - heard that, but (<a b c>) seems to make a List 09:06
Nemokosch welp, then I'm not sure why that flattened
<a b c> itself makes a List
Mason yep, I saw that all in the docs 09:07
Nemokosch m: dd <a b c>
jaguart Oh - that is nice :)
Nemokosch for [('a', 'b', 'c')] being flat, well... apparently it is but I wouldn't have expected it... 09:08
maybe I've read this before but even after more than one year of pretty intensive scripty use of Raku, I couldn't adopt my mind to this 09:09
I mean adding the scalar sigil is an easy fix but still, just why 09:10
m: dd [$<a b c>]
09:11 discord-raku-bot left, discord-raku-bot joined
jaguart maybe cos List is immutable, Array is List of scalar containers 09:12
m: <a b c>[1] = 'B' 09:13
camelia Cannot modify an immutable List ((a b c))
in block <unit> at <tmp> line 1
Nemokosch you can put the List into a scalar container
jaguart m: [<a b c>][1] = 'B' 09:14
camelia ( no output )
Nemokosch $<a b c> returns (Nil, Nil, Nil) and I think I know why...
syntactic ambiguity with hash lookup 09:15
jaguart oh - so a hash-slice
Nemokosch it looks up keys 'a' 'b' and 'c' on the anonymous $ variable ๐Ÿ˜†
$(<a b c>) works as expected 09:16
the list living inside a Scalar
jaguart is that the List inside the anonymous $ state var? 09:23
m: say (%)<a b c> 09:24
camelia ((Any) (Any) (Any))
jaguart m: say ($)<a b c>
camelia ((Any) (Any) (Any))
Nemokosch m: dd $(<a b c>)
yeah I suppose you don't see the output of this, I might switch to IRC for now 09:25
09:25 Nemokosch joined
jaguart m: dd $(<a b c>) 09:25
camelia $("a", "b", "c")
Nemokosch off we go
jaguart m: dd (<a b c>)
camelia ("a", "b", "c")
Nemokosch you know, what bugs me is the difference between (1) and [1] 09:26
m: dd [1]
camelia [1]
Nemokosch actually an array
m: dd (1)
camelia 1
Nemokosch just the number
jaguart m: dd 1,
camelia 1
Nemokosch but then why does [['a', 'b', 'c']] flatten? 09:27
jaguart - I think your idea was good but maybe the comma got passed as an argument separator for the function 09:28
09:29 discord-raku-bot left
Nemokosch and I'm not sure one can disambiguate without using parens 09:29
09:29 discord-raku-bot joined
jaguart or whatever? aka ;* 09:30
m: say [[1,2,[3,4]],[4,5]][*;*];
camelia (1 2 [3 4] 4 5)
jaguart m: say [[1,2,[3,4]],[4,5]][*;*;*;*] 09:31
camelia (1 2 3 4 4 5)
Nemokosch this is multi-dimensional indexing
jaguart yeah - I'm wondering if an implied whatever is flattening when you dont expect it 09:33
or maybe its the flattening semi-colon 09:34
Nemokosch the semi-colon is, from what I know, I shorthand for nesting 09:35
m: say [[1,2,[3,4]],[4,5]][*][*];
camelia ([1 2 [3 4]] [4 5])
Nemokosch welp, it did NOT do the same
could you direct me to the documentation where you found that ; flattens? 09:36
Nemokosch thank you
jaguart yw - but Im no longer a welp ;)
09:37 Kaiepi joined
Nemokosch so apparently subscripts of subscripts simply don't count as "multidimensional" 09:43
I thought ; was just syntax sugar for subscripts of subscripts
it still might be a syntax sugar but surely not for that :D 10:01
lizmat if you look at the 6.e code for that, you will see it makes more sense I think 10:08
10:13 Nemokosch left 10:14 Nemokosch joined
Nemokosch gotcha 10:50
I like how CoreHackers::Sourcery is based on introspection and therefore works with certain language versions 10:51
12:02 sgrs joined 13:37 habere-et-disper joined
habere-et-disper How do you subset an Array? 13:42
If I take a working subset of Int like:
m: subset pint of Int where 1..*; sub pirate( pint $n ) { say $n }; my pint $foo = 120;
camelia ( no output )
habere-et-disper And adjust it to an Array, I'm confused by the type check failure:
m: subset parr of Array where { .elems ~~ 2..* }; sub pirate( parr @n ) { say @n }; my parr @foo = [120,2];
camelia Type check failed for an element of @foo; expected parr but got Int (120)
in block <unit> at <tmp> line 1
habere-et-disper Thanks!
13:43 razetime left
Kaiepi m: subset parr of Array where { .elems ~~ 2..* }; sub pirate(parr \n) { say n }; my parr $foo = [120,2]' 13:49
camelia ===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> rr \n) { say n }; my parr $foo = [120,2]โ'
expecting any of:
infix stopper
statement end
Kaiepi huh
m: subset parr of Array where { .elems ~~ 2..* }; sub pirate(parr $n is raw) { say $n }; my parr $foo = [120,2]'
camelia ===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> raw) { say $n }; my parr $foo = [120,2]โ'
expecting any of:
infix stopper
statement end
Kaiepi that works in raku -e?
anyway a type on an @ or % sigilled parameter types its elements, not the container 13:50
you need either an $ is raw or \ to be most equivalent
you can get away with just $ sometimes though 13:51
Anton Antonov <@210313526928080896> Instructive explanations above! 14:07
What is the easiest way to get list if lists threaded? Here is an example of what I mean: from `(3,5,(10,20),100)` to get `((3, 5, 10, 100), (3, 5, 20, 100))` . 14:12
habere-et-disper Thanks Kaiepi! 14:13
Kaiepi <@694526400488669234> not sure offhand. could make a weird `reduce`? 14:32
Anton Antonov <@210313526928080896> Sure, a weird reduce would work! ๐Ÿ™‚ I assume that means using `reduce` with the `X` , `Z` , etc. operators. 14:34
Nemokosch m: [X] (3,5,(10,20),100) 14:36
m: say [X] (3,5,(10,20),100)
Kaiepi m: say [X] (1,2,(3,(4,5),6),7) 14:37
you'd need to repeat that for each layer of list
Nemokosch I don't even know what is the expected semantics tbh
Anton Antonov Ok, let me post a more general case. 14:39
Kaiepi i see it as being a product of sorts
14:40 habere-et-disper left
Nemokosch but what exact sort? 14:41
"flatten out" using this cartesian product from inside out recursively?
hm, not sure if what I said even makes sense xd 14:42
Kaiepi idk 14:43
Anton Antonov Imagine I have this kind of expression: `a1 + a2 + (b1, b2, (c1, c2, c3)) + b3` . _One way_ to interpret it is like this: `(a1 + a2 + b1 + b3, a1 + a2 + b2 + b3, (a1 + a2 + b3 + c1, a1 + a2 + b3 + c2, a1 + a2 + b3 + c3))` . 14:46
Nemokosch ๐Ÿคจ 14:49
Anton Antonov You can see that there are some distinct threads of summation, that follow the original shape of the list.
Nemokosch why did the c's go to the end?
Anton Antonov Ah, sorry, alphabetical sorting... 14:50
Nemokosch for me, it seems that (b1, b2, (c1, c2, c3)) was exactly like (b1, b2, c1, c2, c3) would have been
Anton Antonov And assuming `+` is associative.
Well, no that produces: `(a1 + a2 + b1 + b3, a1 + a2 + b2 + b3, a1 + a2 + b3 + c1, a1 + a2 + b3 + c2, a1 + a2 + b3 + c3)` . 14:53
Nemokosch what is the difference? 14:54
Anton Antonov A big one -- one level of summation is lost. 14:55
Thanks for considering this problem -- I have to find a better description for it. (And maybe post in StackOverflow.)
Nemokosch the number of sums is the same 14:56
14:59 mcmillhj joined
mcmillhj With given/when is it possible to match against two values? Something like `given ($A, $B) { when (1, 5) { .... } };`. `$A` and `$B` are unique so I can concatenate them together to match against but it doesn't look as clean to me for some reason. I tried using a Pair but it isn't quite working. 15:01
Nemokosch with "either-or" semantics? 15:02
ohh, okay, nevermind 15:03
list semantics
mcmillhj yes, I want to consider both values. 15:04
This was my first attempt:
Nemokosch why does it not look clear? ๐Ÿฅบ
clean* 15:05
Anton Antonov <@297037173541175296> Let me program those examples in Mathematica and make corresponding expression plots. Maybe, it will make more sense. To both you and me... ๐Ÿ™‚
mcmillhj Using Pairs does look clean :) Unfortunately it produces the wrong answer when compared to this method using concatenation: 15:06
Nemokosch I beg to disagree that it looks clean. I don't think Pairs are meant for that. The bigger problem is that the current behavior might contradict the documentation. 15:08
mcmillhj: what version of Raku are you using? 15:09
I have something to show you 15:14
mcmillhj v2021.04. 15:18
raku v6.d
the documentation would actually explain why it doesn't work for you - but the documentation would be wrong. It's fixed by now. 15:19
15:20 Nemokosch left
It's a good idea to keep an up-to-date Rakudo instance. What OS are you using? 15:20
mcmillhj I am not sure I am following. That's the substitution operator right? 15:21
macOS, let me update it in brew
Nemokosch `~~` is the smartmatch operator - the operator `when` happens to use 15:22
mcmillhj what does the `:` prefix do? 15:25
Nemokosch it's a "colon pair" syntax, for numbers in particular 15:26
`:42z` stands for `z => 42`
smartmatching of pairs didn't use to take the key into account - however, it seems this was deliberately changed this year 15:27
mcmillhj I feel like I am being dense, but what does this mean exactly. If it is considering the key shouldn't it be matching correctly? 15:30
or you are saying this is patched in a newer version of rakudo that I don't have?
Nemokosch the latter 15:31
mcmillhj yep, I'm dumb sorry :) That makes total sense and after updating rakudo-star just now it produces the same result as the concatenation method. Thanks so much for your help @Nemokosch 15:32
Nemokosch apparently it wasn't clear if the behavior you were witnessing is correct or not; roughly a year ago, core devs reached the conclusion that it was wrong. The documentation is not yet updated (gonna take care of that) but you can update your version of Rakudo and then it will work as you want ๐Ÿ™‚
cool ๐Ÿฅณ
15:33 Nemokosch joined 15:35 Nemokosch1 joined 15:38 Nemokosch left 16:42 Nemokosch1 left 19:00 mcmillhj left 21:07 NemokoschKiwi joined 21:59 NemokoschKiwi left 23:22 deoac joined
deoac given `Hash %foo` how do determine if `%foo{"bar"}` exists regardless of the case of `bar` ? 23:23
Nemokosch can't you just store all the keys lowercase for example? 23:24
deoac The Hash comes from a user over whom I have no control (except to verify that the Hash is legit). 23:53
Nemokosch 'bar' (elem) %foo.keys>>.uc ? 23:57
oops, I meant lc 23:58