Is it possible to define a new operator in Raku and control its precedence?

231 views Asked by At

Consider this new operator:

sub infix:<*++>(\num1, \num2) {
    num1 * num2 + 1
}

say (2 + 1 *++ 3);

This code prints:

10

However, is it possible to control the precedence? Such it behaves like this:

say (2 + (1 *++ 3))

without needing to use parentheses

1

There are 1 answers

2
wamba On BEST ANSWER

It is possible by is tighter

sub infix:<*++> (\num1, \num2) is tighter(&[+])  {
      num1 * num2 + 1
}