MasterDuke tope: btw, about your even earlier question, does `class A is Int { }; multi infix:<+>(A $a, A $b) { say "$a + $b"; A.new(Int.new($a) + Int.new($b)) }; my $a = A.new(3); my $b = A.new(4); dd $a; dd $b; my $c = $a + $b; dd $c` do what you want? 00:21
tope @MasterDuke, yeah it does, that's sort of what I'm gonna do. 00:39
though right now I'm trying to figure out out how to uhh, dynamically add candidates to a multi-sub? or just EVAL them in. e.g. `EVAL q[ multi infix:<+>(MyInt $a, Int $b) { ... } ]` doesn't seem to add the candidate to `&infix:<+>`. and I tried googling for some kind of add_candidate or whatever but was unsuccessful. `.candidates` returns an immutable List it seems 00:41
so after not getting EVAL to add the multi candidate, I found the `&infix:<+>^.add_multi_method` by searching on github, I have no idea what the `$name` argument is, but see they're only added to some temp list, I tried also calling the `incorporate_multi_candidates` but it doesn't seem to have any effect, or I'm misusing it 00:50
but given the fact that these are not documented I'm probably off the beaten path of what's "allowed" in Raku? 00:51
could also use macros to solve this of course but there there's scary warnings of them being experimental 00:52
``` 01:10
> &myadd.signature
(MyInt $a, Int $b)
> &infix:<+>.add_dispatchee(&myadd)
&infix:<+>
> MyInt.new(5) + 1
Cannot iterate object with MVMCode representation (BOOTCode)
> 1+1
Cannot iterate object with MVMCode representation (BOOTCode)
```
yeah getting the distinct feeling of being way off base?
06:28 hexology left
MasterDuke tope: why do you need to dynamically add the candidates? 08:00
gfldex <@93032313142669312> If you need truly dynamic subs, you may have to `use soft`. See docs.raku.org/language/functions#i...t_(pragma) 09:22
@tope#9134 You can use a code generator that produces a `*.rakumod`, thus avoiding macros for the same effect. 09:23
lizmat fwiw, the core has several code generators that generate code to handle the different types of native variables 11:18
SmokeMachine qorg11: you are adding : and => on your parameterā€¦ change it to: `Fifo.new(path => "fifo", :read)` 12:36
tope @MasterDuke: I don't "need" to, I just want to. Current sort of mini-project in learning Raku is to try a little implemention of `ā„¤_n`, i.e. modular numbers. And my thinking was as follows: to inherit from Int so I get all the various stuff you can do with Ints for free, since _in general_ I want them to be treated like Ints (when passed to other code especially); I also want their representation on th 12:49
Anyway, there's a lot of arithmetic like + - / * negation power invert where I'll modify behavior but which is "trivially similar", and also "trivially duplicated", i.e. let's say something like this, the most naive implementation of modular numbers:
```
multi sub infix:<+>(ZModInt $a, Int $b) { ZModInt.new: $a.parent, (Int.new($a) + $b) % $a.parent.modulus }
multi sub infix:<+>(Int $a, ZModInt $b) { ZModInt.new: $b.parent, ($b + Int.new($a)) % $b.parent.modulus }
multi sub infix:<*>(ZModInt $a, Int $b) { ZModInt.new: $a.parent, (Int.new($a) * $b) % $a.parent.modulus }
...```
which is the kind of stuff I feel I should be able to autogenerate within a language (esp. one so dynamic) instead of simply copy-pasting my code in emacs.
not sure if my overly long lines are showing up in IRC properly, but I can hope 12:53
although one small problem I'm having now is this: given 13:16
```
class ZModInt is Int {
has ZMod $.parent; # carrying ring for this number.
# how do I write new/BUILD/bless/anything in order to create instances of this ZModInt for a given Int $value and ZMod $ring?
}```
maybe a really stupid question but I tried various new() w/ self.bless, BUILD(), etc. but can't seem to set both?
MasterDuke have you tried TWEAK? that's generally what to try first, then BUILD, then new 15:18
tope I'm not sure if I'm doing something wrong but TWEAK, BUILD, etc don't seem to get called (when inheriting Int in this way)? 15:41
``` 15:43
class ZModInt is Int {
has ZMod $.parent;
submethod TWEAK(:$parent) {
say "in tweak, attr(undef)=$!parent; arg=$parent";
}
submethod BUILD(:$parent) {
say "in build, attr(undef)=$!parent; arg=$parent";
}
}
my $F = ZMod.new(modulus=>19);
my $w = ZModInt.new(11, parent=>$F);
```
something like this? is there any place I can read about the differences between, say, `is Int` and how it's different from a regular class, like documentation?
the only thing that seems to be called is `new()` but I'm not sure how to express uhh, "go ahead and initialize `Int self` to $x please, while also setting $!parent to $y" in Raku 15:47
17:46 guifa joined
thowe it's strange that Perl 6 and Raku seem to be treated as separate languages by github. I wonder if there is a good solution to that... 22:51
23:12 gfldex_ joined 23:17 MasterDuke left, gfldex left 23:19 gfldex_ is now known as gfldex 23:20 MasterDuke joined
tope re this, in case anyone finds my problem through search, I half-figured out how to do it by trial and error, in that I would have a `multi method new($mod, $value)` which can do `callwith($value)` to force Raku to construct the actual object for me (which will correctly be my class and not just `Int`), and then this I can return from `new` after calling for example `BUILD(parent=>$mod)` or whatever else 23:38