Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 394
Julio Avatar asked Oct 13 '20 17:10

Julio


Video Answer


1 Answers

It is possible by is tighter

sub infix:<*++> (\num1, \num2) is tighter(&[+])  {
      num1 * num2 + 1
}
like image 104
wamba Avatar answered Oct 24 '22 22:10

wamba