Search code examples
operatorsoperator-precedencerakurakudo

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


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


Solution

  • It is possible by is tighter

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