Front page | perl.perl6.users | Postings from March 2021

## Re: 'CALL-ME' Math problem?

From:
Wenzel P. P. Peppmeyer
Date:
March 13, 2021 20:16
Subject:
Re: 'CALL-ME' Math problem?
Message ID:
1a9477e8-9324-1304-e8a0-1c4cd79d6315@gmx.de
```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

```