[03:28] *** jgaz left [10:47] *** dakkar joined [15:15] *** jgaz joined [16:46] *** jgaz left [17:39] *** jgaz joined [17:39] *** discord-raku-bot left [17:40] *** discord-raku-bot joined [17:48] 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:55] *** discord-raku-bot left [17:55] *** discord-raku-bot joined [18:31] *** dakkar left [18:34] @tope#9134 method calls can not be static [18:50] @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:58] https://github.com/rakudo/rakudo/blob/master/src/core.c/Numeric.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. [18:58] 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 [18:58] There is no operator for `Numeric` that is called `infix:<+>` The operator in the body of that function is a nqp-level thing. [19:00] If you want to build a custom `Int` you have to define that and all relevant operators. [19:00] 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 [19:00] You can do that. [19:03] m:``` [19:03] class C { [19:03] multi method m (Int $) {} [19:03] multi method m (Str $) {} [19:03] } [19:03] C.new.^methods.grep(*.name eq 'm')[0].candidates.say; [19:03] ``` [19:03] 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 [19:04] ah yeah, the Raku-side loop is what I was hoping to avoid [19:04] in that there might be some built-in lookup [19:04] A mathod can be a multi and if so `.candidates` gives you just that. [19:04] in the VM or something like that [19:04] However, if you depend on that you may get unexpected behaviour. [19:06] 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 [19:06] and constructs the + - * etcs [19:06] for me [19:06] Your best bet is to leave the dispatch to he VM. [19:10] If you want to learn more about dispatch I got a few blog posts https://gfldex.wordpress.com/2021/02/17/method-ish/ [19:13] 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:` 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:15] 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] You can create the methods with EVAL and add them to a type at runtime (or late compile time) with the MOP. [19:21] thanks for the link by the way, though most of this stuff is a bit over my head / black magic to me currently [19:23] 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 [19:25] 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:26] *** jgaz left [19:27] you can find a list of the gnarly things here: https://github.com/Raku/nqp/blob/master/docs/ops.markdown [19:29] 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] lets have a look then [19:29] or be that infix:<%%> or whatever, all of those special operator things [19:30] m:``` [19:30] &infix:<+>.WHAT.say; [19:30] ``` [19:31] m:``` [19:31] &infix:<+>.^methods.say; [19:31] ``` [19:31] ohh well, loads of ForeignCode-stuff [19:32] m: &infix:<+>.candidates.say; [19:32] oh, & and .candidates directly [19:32] i see [19:33] m: &infix:<+>.candidates».signature.map(*.raku ~ $?NL).say; [19:35] m: &infix:<+>.candidates[1].&{[.file, .line]}.say; [19:43] 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:45] ye, you need a sigil to access the value. In the case of callable things, the sigil is &. [19:54] 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:56] m: dd (^(2**512)).roll [19:56] rakudo-moar a10042dd9: OUTPUT: «12953970012897700864089812190051486424997541595083123902596280172005301588347796418283225018562644769732031070637482555367270225904952351039637380171584616␤» [20:03] 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:04] There are modules for that (that may cheat by using a C-lib). [20:05] sure, easy to just paste in a PCG, just surprised it's not standard when `rand` is even a _term_ like `self`.. [20:07] randomness is a hard problem [20:10] 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 [20:11] or no, maybe that's in nqp [20:14] m: use nqp; [20:14] say nqp::rand_I(2**512, Int); [20:14] rakudo-moar a10042dd9: ( no output ) [20:14] m: use nqp; say nqp::rand_I(2**512, Int); [20:14] rakudo-moar a10042dd9: OUTPUT: «7330542640256188006484191078491594074521673809110991115833721087159586890574389728704739296559954083024684615551583518543690538207896602021586278415868496␤» [20:15] yes! [20:15] o.O [20:16] lizmat: did we overlooked Int.rand? [20:16] gfldex: am spectesting that right now :-) [20:17] @tope#9134 well spotted! [20:19] 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:21] 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:24] gfldex: some small fallout with mixes [20:33] lizmat: does JVM agree? We tend to "overlook" simple things because JVM is what it is. [20:35] I don't know if the JVM agrees, I've come to depend on bartolin++ for that [20:39] https://github.com/rakudo/rakudo/pull/4692 [20:39] gfldex tope ^^ [20:54] \o/ [20:54] praise the integers [21:28] *** MasterDuke joined [21:30] tope: moarvm still uses libtommath. i have a 99% complete switch to GMP (https://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:52] *** jgaz joined [21:53] *** jgaz left [21:58] https://ls.qorg11.net/files/PELgKKnY/-.txt any hjelp with this? [22:06] qorg11: you may need ::?CLASS:U: in your .new methods. [22:07] any doc? [22:09] Unless you have a good reason for overloading .new, you are better off with BUILD https://docs.raku.org/language/classtut#index-entry-BUILD [22:10] or TWEAK [22:10] qorg11: the error message does tell you what the compiler expects tho: `new(Fifo:U: ` [22:10] `Fifo` is undefined, so you need the undefined invocant. [22:25] 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] s/can/can't/