🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
Tirifto Bridge and Real were not mentioned in the documentation on ‘Context and contextualizers’. I wonder if there’s a better place I should have searched in? Or should there be no single page in the official documentation to learn all of this from? `o` 00:00
avuserow Yes, I agree. I actually only knew this because I implemented a module using this many years ago. Though I don't remember what the minimum requirements are, and I'm still a bit confused on getting the `+` operator to work. 00:08
"I agree" in the sense that this should be documented in a single consistent place, since this is very useful in the right domain :) 00:09
m: class Foo does Real {has Int() $.data; method Bridge { $!data }; method succ {self + 1}}; multi sub infix:<+>(Foo $a, Real $b) {Foo.new(:data($a.data + $b))}; my $f = Foo.new(:data(3)); $f++; say $f; say $f.WHAT; my $f2 = $f + 1; say $f2; say $f2.WHAT; my $f3 = $f + $f2; say $f3; say $f3.WHAT 00:13
camelia 4
(Foo)
5
(Foo)
9
(Foo)
avuserow I feel like there's a better way than re-implementing all the math operators, but maybe it depends on how you want your type to behave? 00:16
e.g. do you need `$f++` to return a Foo instance? `$f--`? `$f * 4`? and not to mention if there's a Foo and Bar, which one wins? 00:20
docs.raku.org/type/Real#method_Bridge has more details 00:22
guifa so one of the catches making a new number class isn't so much reimplementing the math operators but making sure that they work globally 01:46
that's not in and of itself hard, but it deoptimizes all over the place
right now, the best way that I know how to do it is to wrap each infix, and wrapping is slooooow 01:47
If there were a way to add multi candidates at the global level that would solve things and probs not kill optimizations but I don't think there is a way, and I'm not sure there will be a way 02:07
guifa (at least, no official way. I think you could do some under the hood magic by violating OOP to adjust the @!dispatchees and @!dispatch order maybe) 02:22
Nemokosch To be fair, the abstraction is correct. It's not an intrinsic property of numbers that they are ordered 08:08
It is, however, an intrinsic property of real numbers 08:09
Anton Antonov This link in the documentation does not work: docs.raku.org/syntax/identifiers.h...dentifiers . Linked from: docs.raku.org/language/optut.html . 14:20
guifa should be docs.raku.org/language/syntax#Exte...dentifiers 14:29
librasteve you can open an issue here github.com/Raku/doc/issues 18:36
Anton Antonov Will do — thanks! 18:37
librasteve 👍
Tirifto Has anyone perchance used the NCurses package by azawawi? `o` 18:57
There’s a set of functions (getstr, getnstr, wgetstr, etc.) which take a string as an argument (char* in C, Str in the Raku binding), and are supposed to read a string from input and store it there. But when I pass a String to one of these functions, its value never changes. 19:25
The library uses NativeCall and I tried adding ‘is rw’ to the Str argument (though by my understanding that shouldn’t be necessary), but to no avail. So I’m not sure if I’m doing something wrong, or if the library is, and in the latter case, if it might be simple to fix or not. `o` 19:27
librasteve Tirifto: i haven't used before but just installed (rakubrew, mac, zef) and the synopsis runs fine for me --- can you provide your code in a gist maybe? 20:43
sorry must to bed - another good place to ask is stackoverflow with the [raku] tag... 20:52
Tirifto Good night, librasteve. 20:53
I have uploaded an example here: tirifto.xwx.moe/d/curse.raku