This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
tonyo it can but only by the developer, internally you probably don't know which one they mean and if the parameters are more ambiguous you can't really recommend 00:08
here's how fez does it: github.com/tony-o/raku-fez/blob/ma...kumod#L663 00:14
i write pre-formatted usage docs for each command and put them in the resources to make it easier for me
00:46 discord-raku-bot left, discord-raku-bot joined 01:48 teatime left
rcmlz I was noth considering the multi case situation - you are right, in such situations it would be difficult for Raku to know what parameter to consider for blaming „wrong value for parameter xyz“. Thank you for clarifying. I guess I do need to invest some time into tuning GENERATE-USAGE. 05:43
08:15 dakkar joined
antononcube How can I program the postcircumfix operator for shaped arrays access? For a certain class/object I work on I want to access elements of it with $obj[3;1] . 08:20
I tried to use postcircumfix:<[ ]> withot success...
lizmat <[;]> 08:22
antononcube @lizmat 🙂 I tried that but put a space in it postcircumfix:<[; ]> ... 08:23
@lizmat I have been skimming / reading "Array::Sparse" a lot in the last few days. 08:27
Maybe, at some point I will figure out how to use in my Sparse Matrxi project. (Or "Array::Agnostic".) 08:28
lizmat :-)
antononcube I get this error now -- and I cannot figure out what to do: > Not enough symbols provided for categorical of type postcircumfix; needs 2 08:31
Here is my code: multi sub postcircumfix:<[;]>(Math::SparseMatrix::CSR:D $mat, $i, $j) { $mat.value-at($i, $j) }
lizmat perhaps ($mat, *@args) ? 08:32
antononcube Hmm.. I tried that too, same error. 08:35
lizmat confirmed... 08:36
looks like it needs to be <; ]> 08:38
sorry, <[; ]>
with a space after ;
antononcube looks like you're going to need to go through some hoops 08:42
looks like the multi sub is not getting selected 08:43
antononcube Hmm... ok. (Again, I did try "[; ]", with the space first.) 08:47
lizmat looks like there's something in dispatch that's not triggering correctly for <[; ]> :-( 08:50
my gist so far: gist.github.com/lizmat/c9cecea61e1...e177bd556d 08:51
ab5tract a temporary alternative could be to dispatch to a private multi with a less tricky name 09:39
lizmat m: class A { }; proto sub postcircumfix:<[; ]>(|) {*}; multi sub postcircumfix:<[; ]>(A:D) { dd }; multi sub postcircumfix:<[; ]>(|c) { dd }; (A.new)[0;0] 09:42
camelia sub postcircumfix:<[; ]>(|c)
lizmat so why is it selecting the |c candidate ? 09:43
oops, that is actually correct
m: class A { }; proto sub postcircumfix:<[; ]>(|) {*}; multi sub postcircumfix:<[; ]>(A:D, |c) { dd }; multi sub postcircumfix:<[; ]>(|c) { dd }; (A.new)[0;0]
camelia Ambiguous call to 'postcircumfix:<[; ]>(A, List)'; these signatures all match:
(A:D $, |c)
(|c)
in block <unit> at <tmp> line 1
09:44
ab5tract m: class A { }; proto sub postcircumfix:<[; ]>(|) {*}; multi sub postcircumfix:<[; ]>(A:D, |c) { dd }; multi sub postcircumfix:<[; ]>(|c) { dd }; (A.new)[A.new;0]
camelia Ambiguous call to 'postcircumfix:<[; ]>(A, List)'; these signatures all match:
(A:D $, |c)
(|c)
in block <unit> at <tmp> line 1
ab5tract m: class A { }; proto sub postcircumfix:<[; ]>(|) {*}; multi sub postcircumfix:<[; ]>(A:D, |c) { dd }; multi sub postcircumfix:<[; ]>(|c) { dd }; (A.new)[A.new;]
camelia Cannot resolve caller Int(A:D: ); none of these signatures matches:
(Mu:U \v:: *%_)
in block <unit> at <tmp> line 1
ab5tract m: class A { }; proto sub postcircumfix:<[; ]>(|) {*}; multi sub postcircumfix:<[; ]>(A:D, |c) { dd }; multi sub postcircumfix:<[; ]>(|c) { dd }; (A.new)[A.new;A.new]
camelia Ambiguous call to 'postcircumfix:<[; ]>(A, List)'; these signatures all match:
(A:D $, |c)
(|c)
in block <unit> at <tmp> line 1
lizmat perhaps we should take this to #raku-dev 09:45
ab5tract okay, sorry camelia, I know you don't like to be spammed
lizmat++
lizmat antononcube the sub must be: multi sub postcircumfix:<[;]>(Math::SparseMatrix::CSR:D $mat, @args) { $mat.value-at(@a[0], @a[1]) } 09:49
*@args[0], @args[1]
the number of elems in @args indicates the number of dimensions 09:50
antononcube @lizmat Ok, great — Thank you! 12:48
lizmat the reason is that each element in the @args could well be a list itself :-) 12:49
$mat[0; 20..30]
librasteve lol --- often the raku-beginner channel is about the same level as python core ;-) 13:48
antononcube @librasteve Thanks for posting this: stackoverflow.com/q/70976231 14:06
You posted both the original and the working solution code.
librasteve always happy to share how smart I am 14:08
(or more correctly the results of much trial and error) 14:09
not sure if it says in the post, but the released code is in raku.land/zef:librasteve/Dan 14:10
I would draw your attentioon to cascading accessors (which were in the PDL part of the synopses, but not imolemented) - maybe would make sense to isolate and package just that code... 14:11
lizmat librasteve could you tell me which part of the code you're talking about ? 14:25
antononcube I think the methods .splice , .aop, etc. 14:28
@librasteve Also, what is "PDL" ? Perl Data Language? 14:29
librasteve PDL … yes that was an early concept for perl Numpy iiuc 14:49
lizmat: sorry I’m on the road, let me try anyway … in the Dan repo /bin/synopsis.raku has a section called Value Accessors which shows the API 14:52
the 2d code for class DataFrame is at /lib/Dan.rakumod ll745 under Role Support 14:55
antononcube Can I, should I implement postcircumfix:<[ ]> as a class method? It seems the method approach is not working. 15:18
lizmat antononcube if your class implements methods AT-POS and friends, you shouldn't have to need to make postcircumfix subs ? 15:19
m: class A { method AT-POS(|c) { dd c } }; A.[42] 15:20
camelia \(42)
lizmat n: class A { method AT-POS(|c) { dd c } }; A.[42,666]
m: class A { method AT-POS(|c) { dd c } }; A.[42,666] 15:21
camelia \(42)
\(666)
antononcube Yes, I tried AT-POS -- works nicely with a single, integer argument, e.g. $obj[3] . But when use a spec like $obj[2, 3, 1] it gives me a list of single argument applications, like, ($obj[2], $obj[3], $obj[1]) which is not what I want -- a new $objc has to be made corresponding to (2, 3, 1). 15:26
Hence, I am investigating postcircumfix:<[ ]> and postcircumfix:<[;]>.
tonyo antoncube, you figure it out? 15:44
antononcube @tonyo Not completely. 🙂 15:48
16:34 dakkar left
tonyo m: class A { has $.b; }; sub postcircumfix:<[ ]> (A:D $a, **@as) { dd $a.b; dd @as; }; my $a = A.new(b=>5); $a[1,2,3]; 17:02
camelia 5
[(1, 2, 3),]
tonyo something like that ^ ?
are you trying to use a tuple keyed hash or something?
antononcube @tonyo Thanks -- trying that out now. 17:05
@tonyo These tests might clarify what I am looking for : github.com/antononcube/Raku-Math-S...s.rakutest 17:06
In addition I would like to make "slices" like: 1) $mat[4;5] 3) $mat[1..3;2...6] 17:07
tonyo if you need to use private stuff in there:
m: class A { has $!b; method AT-POS(*@as) { dd @as; } }; sub postcircumfix:<[ ]> (A:D $a, **$as) { $a.AT-POS(|$as); }; my $a = A.new(b=>5); $a[1,2,3]; $a[2]
camelia [1, 2, 3]
[2]
tonyo ^ that works with $a[1..3] and $a[1;3] too
antononcube @tonyo These work to a point -- thanks! 17:32
But if I add the lines: my @b = 33, 12, 23, 3, 6; say @b[1,2]; I get the error: > Type check failed in binding to parameter '$a'; expected A but got Array ([33, 12, 23, 3, 6]) 17:33
It looks like adding multi to my special definition of postcircumfix:<[ ]> fixes the problem with typycal arrays. 20:01
ab5tract antononcube: careful with the likely unintentional use of the sequence operator here: $mat[1..3;2...6] 20:46