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.
00:48 MasterDuke joined 01:27 Manifest0 left 03:55 CIAvash joined 09:37 CIAvash left 12:13 Manifest0 joined 14:35 notna joined 15:12 notna left
Tirifto Is there a natural way to provide a subset with its own method, or conversely, a class with its own constraint? `o` 20:39
MasterDuke m: subset N of Int where * > 1; N.^add_method("foo", method { say "bar" }) 20:42
camelia No such method 'add_method' for invocant of type
'Perl6::Metamodel::SubsetHOW'
in block <unit> at <tmp> line 1
MasterDuke so can't do exactly that right now. maybe just need to add `does Perl6::Metamodel::MethodContainer` to Perl6::Metamodel::SubsetHOW and then ^^^ would work 20:44
Tirifto So if I want to keep things simple, I’m probably better off creating an intermediate class and then making a subset of that, right? ^ ^’ 20:47
MasterDuke but for a class with a constraint, you could probably just add a check in its `.new`, right? something like `class N { has $.foo; method new($foo) { die if $foo eq "bar" }; }; say N.new("bar").foo' 20:50
yeah, think we're saying the same thing
Tirifto MasterDuke, but would that work for existing values (of the superset type) being assigned to containers of the class, and would that catch all possible ways of creating the value? `o` 20:55
MasterDuke i'm not sure. could try pinging vrurg or lizmat, they'd probably have a better idea 20:57
Tirifto I’ve tried subsetting an anonymous class, but that seems invalid. 20:59
m: subset N of (class { also is Int; method foo { say “bar” } }) where * ≥ 1;
camelia ===SORRY!=== Error while compiling <tmp>
Malformed trait
at <tmp>:1
------> subset N of⏏ (class { also is Int; method foo { say
ab5tract Tirifto: I don't think using a constraint in the constructor would solve those concerns, unfortunately
you could define a custom `STORE` on the class to constrain the assignments 21:03
docs.raku.org/language/subscripts#method_STORE 21:04
that plus constraining in `new` (or `TWEAK`) should do what you want, I think 21:05
(if I'm understanding you correctly, of course) 21:07
ahh, wait, that's only for positionals :( 21:14
well, positionals and associatives 21:17
I don't think that this isn't exactly what you are looking for, but maybe this could help? docs.raku.org/language/containers#...containers 21:18
*is exactly 21:20
Tirifto ab5tract, oh, that looks very interesting. :o 21:33
For my current program, I think I’ll get by with using a subroutine instead of a method (with the argument constrained to the subset) in the end. cx 21:38
Thank you for the link though; I don’t think I’ve noticed custom containers before! 21:40
m: my $p = (a => 1); say $p.WHAT; say $p.kv.WHAT; 21:45
camelia (Pair)
(Seq)
ab5tract no problem! the core of it is the unfortunately under-documented `Proxy` class: docs.raku.org/type/Proxy 21:48
Trifito: for your last `m` invocation, did you have different expectations? 21:50
Tirifto ab5tract, actually yes! The documentation says that .kv on a Pair should return a List, but here it returns a Seq. I’d expect the return type to indicate that I should get a List or a subclass thereof. :o 21:52
ab5tract Hmmm, I think the docs are out of date on that 21:53
everything else, including List.kv, returns a Seq 21:55
Tirifto Any idea if the signatures in the documentation are automatically generated? This also happens on Rakudo 2022.12, so I assumed the on-line docs would’ve been refreshed with the correct signatures since, if that were the case. `o` 21:56
ab5tract m: my $p = (a => 1); say $p.WHAT; say (|$p.kv).WHAT;
camelia (Pair)
(Slip)
ab5tract the documentation is not automatically generated, though there have been movements in that direction 21:57
Tirifto Oh! 21:58
ab5tract I'll create a bug report on the docs now
Tirifto Thanks a lot! ^ ^ 21:59
ab5tract bisectable: (a => 1).kv.WHAT ~~ List 22:02
Tirifto: for what it's worth, the Seq from .kv will "act like" a List 22:07
but if I understand correctly you are trying to interact with the type of Pair.kv's output, not the values directly 22:08
Tirifto ab5tract, it’s actually the values; I just noticed the type mismatch when investigating the issue and thought it might be the cause, but finally that doesn’t seem to be the case. 22:13
ab5tract ah ok that's good then
Tirifto The issue I ran into was apparently the hyper method call operator (».) not behaving as I expected it to, while .map does behave as I expect it to. cx 22:14
m: my @pairs = (a => [1, 2, 3], b => [4, 5, 6]); @pairs».kv; say @pairs».kv».Slip; say @pairs».kv».Slip; say @pairs».kv.map(*.Slip); 22:15
camelia ((a [1 2 3]) (b [4 5 6]))
((a [1 2 3]) (b [4 5 6]))
(a [1 2 3] b [4 5 6])
Tirifto The documentation talks about the nodality of the method invoked being important for »., so I assume the difference boils down to that. 22:16
(I make that assumption while not being sure what exactly nodality is, and it seems like it might take a while for me to understand properly, so I’m content just knowing I’m better off using map for the time being if that’s the case. xP) 22:18
(… okay, the description of ‘is nodal’ actually outlines it pretty clearly, but I’m still not exactly sure what the two do differently. I guess .map calls .Slip on (a [1 2 3]), while ». presumably calls it on a, 1, 2 and 3? `o`) 22:23
ab5tract ah, yeah, I find that it can be a very subtle distinction indeed 22:34
m: my @pairs = (a => [1, 2, 3], b => [4, 5, 6]); say @pairs».kv».reverse; say @pairs».kv.map(*.reverse); 22:37
camelia (([1 2 3] a) ([4 5 6] b))
(([1 2 3] a) ([4 5 6] b))
ab5tract oops, needs the Slip 22:38
m: my @pairs = (a => [1, 2, 3], b => [4, 5, 6]); say @pairs».kv».Slip».reverse; say @pairs».kv.map(*.Slip).map(*.reverse); 22:39
camelia (([1 2 3] a) ([4 5 6] b))
((a) (3 2 1) (b) (6 5 4))
ab5tract I'm not sure if that actually helps elucidate it or not.. it's a bit late where I am to be thinking too hard about is nodal :) 22:40
the most important thing to remember is that » and map are not always equivalent when dealing with more complex nestings 22:41
Tirifto: happy hacking! I'm off for tonight 22:42
Tirifto m: my @pairs = (a => [1, 2, 3], b => [4, 5, 6]); say @pairs».kv».Slip.map(*.reverse)
camelia (([1 2 3] a) ([4 5 6] b))
Tirifto Er— did not meant to send that.
Thank you, ab5tract, and have a good night!
I’ll remember the most important thing and meditate further on the rest. xP 22:43