03:28 jgaz left 10:47 dakkar joined 15:15 jgaz joined 16:46 jgaz left 17:39 jgaz joined, discord-raku-bot left 17:40 discord-raku-bot joined
tope q: how do I refer to a specific multi-method (statically)? let's pretend `class MyInt is Int {};` and then I want certain arithmetic ops to simply defer to Int's arithmetic but to produce `MyInt`s still, e.g. `multi sub infix:<+>(MyInt $a, Int $b) { MyInt.new: [...??...]($a, $b) }` <-- what does one put here in order to refer to the `&infix:<+>` that is registered for `(Int,Int)`? and preferably I want t 17:48
17:55 discord-raku-bot left, discord-raku-bot joined 18:31 dakkar left
gfldex @tope#9134 method calls can not be static 18:34
tope @gfldex#8222 hmm ok, but still, how would it look like here, for example in Python (in a `class MyInt`) I would do `def __add__(self, b): return int.__new__(MyInt, int.__add__(self, b))` (make `int` generate a new object of type `MyInt` instead of `int`, with the result of the `int.__add__`) 18:50
gfldex github.com/rakudo/rakudo/blob/mast...c.pm6#L211 18:58
@tope#9134 We don't really got that mechanism for very basic buildin types. `infix:<+>` doesn't call any method in `Int` to do the actual math. In fact `infix:<+>` isn't even defined on the Raku level.
tope actually I've wanted to do this earlier too, when I wanted to put a reference to `rand(Num:D --> Num)` into a &container, but didn't know how to access it, since &rand just refers to the argument-less, function
gfldex There is no operator for `Numeric` that is called `infix:<+>` The operator in the body of that function is a nqp-level thing.
If you want to build a custom `Int` you have to define that and all relevant operators. 19:00
tope sure it doesn't have to be a method on "int", I just wondered if there was some way to manually refer to a given candidate(?) when it came to multi subs
gfldex You can do that.
m:``` 19:03
class C {
multi method m (Int $) {}
multi method m (Str $) {}
C.new.^methods.grep(*.name eq 'm')[0].candidates.say;
tope ok good, but is there some special syntax for it, to make a "direct" lookup? or does it involve sort of like, traversing .^candidates or and searching for it? that I am missing. I've sort of gotten lost in all the syntactical tricks of Raku the last few days, so don't feel confident at all I even know half of the possible syntax
ah yeah, the Raku-side loop is what I was hoping to avoid 19:04
in that there might be some built-in lookup
gfldex A mathod can be a multi and if so `.candidates` gives you just that.
tope in the VM or something like that
gfldex However, if you depend on that you may get unexpected behaviour.
tope but I also know that if I start `.grep`ing with a `Whatever` instance on `.^candidates` in every little arithmetic + - * etc for some fairly "low level construct" like an Int-like object, that might in turn be accumulated or calculated in a loop etc, then that's going to be bad news bears in terms of overhead. 19:06
or I guess maybe there could be a trait that does all these lookups
and constructs the + - * etcs
for me
gfldex Your best bet is to leave the dispatch to he VM.
If you want to learn more about dispatch I got a few blog posts gfldex.wordpress.com/2021/02/17/method-ish/ 19:10
tope ok sure, duly noted. though now I'm curious also about another idea, is something like `class MyInt is Int overloads <+ - / *> { }` possible, i.e. writing a `trait_mod:<overloads>` which then does the lookup to find `my &int_add = ... the candidate of + that takes (Int,Int) ...` and then adds, say, `multi sub infix:<+>(MyInt $a, Int $b) { MyInt.new: &int_add($a, $b) }` to the candidate chain? (Or even ju 19:13
from my experience with implementing a lot of algebra/arithmetic stuff in Python, I know I want as little as possible to do with copy-pasting code for all the various arithmetic stuff 19:15
gfldex You can create the methods with EVAL and add them to a type at runtime (or late compile time) with the MOP.
tope thanks for the link by the way, though most of this stuff is a bit over my head / black magic to me currently 19:21
only dynamic language I'm super familiar with the inner workings & dark corners of is Python/CPython 19:23
tho the mechanics of Raku's meta-objects seems not to work like meta-classes in Python so it's sort of back to square 1
gfldex Anything that doesn't pop into existence by virtue of the VM is actually quite accessibly in Raku. You happen to have picked on of those by chance. :) 19:25
19:26 jgaz left
you can find a list of the gnarly things here: github.com/Raku/nqp/blob/master/do...s.markdown 19:27
tope yeah I am getting the impression that everything is highly accessible and introspectable and monkey-patcheable and all that good stuff, however my main hinderance is simply just... syntax. like, ok, back to this basic question: how do I even access infix:<+>'s candidates? there's no syntax to refer to the "multi sub" that is `infix:<+>`? is that what you meant by the earlier comment 19:29
gfldex lets have a look then
tope or be that infix:<%%> or whatever, all of those special operator things
gfldex m:``` 19:30
m:``` 19:31
ohh well, loads of ForeignCode-stuff
m: &infix:<+>.candidates.say; 19:32
tope oh, & and .candidates directly
i see
gfldex m: &infix:<+>.candidatesĀ».signature.map(*.raku ~ $?NL).say; 19:33
m: &infix:<+>.candidates[1].&{[.file, .line]}.say; 19:35
tope yeah, thanks, this gives me much more to play around with, I was missing the & entirely in syntax so was very confused, cause infix:<+> just evaluates to 0. 19:43
lakmatiol ye, you need a sigil to access the value. In the case of callable things, the sigil is &. 19:45
tope oh yeah, another quick question, is there no built-in rand for integers? like let's say I want to get a random 512-bit integer? I hardly want to call rand 512 times for each bit and then sum the powers of two? `rand(^2**512)` unhelpfully says "unsupported use of rand", and `(2**512).rand` gives, counter-intuitively, a float. 19:54
lizmat m: dd (^(2**512)).roll 19:56
camelia 12953970012897700864089812190051486424997541595083123902596280172005301588347796418283225018562644769732031070637482555367270225904952351039637380171584616
tope ah, ok. but that's a bit peculiar/scary, since I would have assumed `(^2**512).roll` would be implemented in terms of the primitive `rand` and so would only have about ~56 bits of randomness in the range... but looking at the source for rakudo at least, it seems to use `nqp::rand_I` which goes off to some tinymt implementation? yet it's just not exposed in other ways? 20:03
gfldex There are modules for that (that may cheat by using a C-lib). 20:04
tope sure, easy to just paste in a PCG, just surprised it's not standard when `rand` is even a _term_ like `self`.. 20:05
gfldex randomness is a hard problem 20:07
tope sure, tho I would argue random bits/integers "easier" than random ieee floats. I expect `rand` itself to be implemented in terms of a generator producing bits/ints. 20:10
like the tinymt that rakudo seems to use
or no, maybe that's in nqp 20:11
gfldex m: use nqp; 20:14
say nqp::rand_I(2**512, Int);
camelia ( no output )
gfldex m: use nqp; say nqp::rand_I(2**512, Int);
camelia 7330542640256188006484191078491594074521673809110991115833721087159586890574389728704739296559954083024684615551583518543690538207896602021586278415868496
tope yes! 20:15
gfldex o.O
gfldex lizmat: did we overlooked Int.rand? 20:16
lizmat gfldex: am spectesting that right now :-)
gfldex @tope#9134 well spotted! 20:17
tope my main interest is rng/cryptography/integers/classical number theory/etc, `Int`s are the first thing I'm going to go for in any new language... 20:19
and happy Raku did the Right Thing (imo) in using GMP (now? used to be tommath?).. as opposed to Python and its homemade bigints. 20:21
lizmat gfldex: some small fallout with mixes 20:24
gfldex lizmat: does JVM agree? We tend to "overlook" simple things because JVM is what it is. 20:33
lizmat I don't know if the JVM agrees, I've come to depend on bartolin++ for that 20:35
github.com/rakudo/rakudo/pull/4692 20:39
gfldex tope ^^
tope \o/ 20:54
praise the integers
21:28 MasterDuke joined
MasterDuke tope: moarvm still uses libtommath. i have a 99% complete switch to GMP (github.com/MoarVM/MoarVM/pull/1402), but there's a problem with the size of longs being different on windows and i haven't debugged that yet 21:30
21:52 jgaz joined 21:53 jgaz left
qorg11 ls.qorg11.net/files/PELgKKnY/-.txt any hjelp with this? 21:58
gfldex qorg11: you may need ::?CLASS:U: in your .new methods. 22:06
qorg11 any doc? 22:07
gfldex Unless you have a good reason for overloading .new, you are better off with BUILD docs.raku.org/language/classtut#in...ntry-BUILD 22:09
MasterDuke or TWEAK 22:10
gfldex qorg11: the error message does tell you what the compiler expects tho: `new(Fifo:U: `
`Fifo` is undefined, so you need the undefined invocant.
qorg11: also, since you define a new proto, you can delegate to Mu.new anymore, what you do with `self.new(:fd => open(:w, :create, $path)` 22:25