On 02/03/2021 09:12, ToddAndMargo via perl6-users wrote:

Math problem:
     x = 60÷5(7−5)

raku -e 'say 60÷5(7−5)'
No such method 'CALL-ME' for invocant of type 'Int'
   in block <unit> at -e line 1

Seems raku does not like the ().  How do I fix this
and maintain the flow and look of the equation?

-T

The correct answer is 24

The correct answer can be found with the following code.

class SuperInt {
    has $.left-factor is rw;
    has $.right-factor is rw;
    method new(\l, \r) {
        my \SELF = self.CREATE;
        SELF.left-factor = l;
        SELF.right-factor = r;
        SELF
    }
}

multi sub infix:<÷>(Numeric:D \l, SuperInt:D \r) {
    l ÷ r.left-factor * r.right-factor
}

Int.^add_method('CALL-ME', my method (\SELF: \v) { SuperInt.new(SELF, v) });
Int.^compose;

say 60÷5(7−5);

Thought, I do have the hunch that this might break with a slightly more
complex examle.

Have -Ofun

gfldex

Reply via email to