🦋 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.
Nemokosch those of you who were wary of Discord turned out to be right painfully soon: www.reddit.com/r/discordapp/commen...nvites_to/ 07:31
Geth Raku-Steering-Council/main: f821d74e24 | (Elizabeth Mattijsen)++ | 2 files
Announcement Richard Hainsworth joining the board
09:25
Anton Antonov Good to know! 11:47
[Coke] wow, I'm out of the loop, congrats to Richard! 13:22
lizmat well, with 5/6 RSC members at the Raku Core Summit, it was hardly any effort at all 13:23
and Richard was there as well, and was on the original ballot, and accepted the invitation, so there's that :-)
Nemokosch sounds like a good choice so Forza 13:30
tonyo . 15:38
tellable6 2023-06-07T23:45:31Z #raku <tbrowder__> tonyo: my suspicion is correct, the book's pseudo code is misleaading and my tests prove it. i'll update the repo in a minute.
tonyo ahh which book are you going through? 15:39
tbrowder__ well knock me down, *I* had the (nonlethal) bug. passed all my tests, but it wouldn't work for overlapping patterns. (book is refernced in the README: Intro to Algorithyms, 3e). see the updated module for all the gory details. 17:15
tbrowder__ module is "AlgorithmsIT" (IT for "Introduction to") 19:27
tbrowder__ finana 20:36
.tell finanalyst congratulations Richard 20:37
tellable6 tbrowder__, I'll pass your message to finanalyst
Tirifto So apparently numeric operators operate (;D) separately from numeric context in Raku. I thought defining the method ‘Numeric’ would let me use the objects of a custom class in numeric comparisons, but it seems the less-than (<) operator requires the method Real instead, as it coerces its operands to Real. 22:45
In other words, if I want a custom class to be usable as (able to be coerced to) a number, I need to care about more than just the numeric context. 22:46
Is that correct? And if so, is there a complete interface the class should implement, perhaps documented somewhere? Or should I just check the behaviour of every operator I might want to use? 22:48
Just asking out of curiosity, for the most part. 22:49
avuserow Tirifto: I think you may just need to implement the Bridge method, and maybe claim that you implement the Real role. 23:21
m: class Foo {has Int $.data; method Bridge { $!data }}; my $f = Foo.new(:data(3)); say $f; $f++; say $f 23:22
camelia Foo.new(data => 3)
No such method 'succ' for invocant of type 'Foo'. Did you mean 'sum'?
in block <unit> at <tmp> line 1
avuserow m: class Foo {has Int $.data; method Bridge { $!data }}; my $f = Foo.new(:data(3)); say $f; say $f + 14; 23:23
camelia Foo.new(data => 3)
Cannot resolve caller Numeric(Foo:D: ); none of these signatures matches:
(Mu:U \v: *%_)
in block <unit> at <tmp> line 1
avuserow Let me look a bit, it's been a while
Tirifto Thank you. ^ ^ 23:25
avuserow m: class Foo does Real {has Int $.data; method Bridge { $!data }}; my $f = Foo.new(:data(3)); say $f; say $f + 14; say $f++; say $f 23:54
camelia 3
17
3
4
avuserow Tirifto: ^^
looks like the minimum viable number needs to implement the Real class, and then have a `Bridge` method that returns the numeric guts. everything else seems to just work 23:55
Tirifto Very interesting! :o Thank you, avuserow. 23:57
avuserow though, if you want `$f + $f` in that example to return an instance of Foo, then you will also need to implement your own `multi method infix:<+>(Foo $a, Foo $b) {...}` 23:58
m: class Foo does Real {has Int $.data; method Bridge { $!data }}; my $f = Foo.new(:data(3)); say $f.WHAT; say $f ~~ Foo; my $f2 = $f + $f; say $f2.WHAT; say $f2 ~~ Foo;
camelia (Foo)
True
(Int)
False
avuserow m: class Foo does Real {has Int $.data; method Bridge { $!data }; multi method infix:<+>(Foo $a, Foo $b) {Foo.new(:data($a + $b))}}; my $f = Foo.new(:data(3)); say $f.WHAT; say $f ~~ Foo; my $f2 = $f + $f; say $f2.WHAT; say $f2 ~~ Foo; 23:59
camelia (Foo)
True
(Int)
False
avuserow m: class Foo does Real {has Int $.data; method Bridge { $!data }; multi sub infix:<+>(Foo $a, Foo $b) {Foo.new(:data($a + $b))}}; my $f = Foo.new(:data(3)); say $f.WHAT; say $f ~~ Foo; my $f2 = $f + $f; say $f2.WHAT; say $f2 ~~ Foo;
camelia (Foo)
True
(Int)
False