In Functions§
See primary documentation in context for Precedence
Operator precedence in Raku is specified relative to existing operators. The traits is tighter
, is equiv
and is looser
can be provided with an operator to indicate how the precedence of the new operator is related to other, existing ones. More than one trait can be applied.
For example, infix:<*>
has a tighter precedence than infix:<+>
, and squeezing one in between works like this:
sub infix:<!!>(, ) is tighter(:<+>)say 1 + 2 * 3 !! 4; # OUTPUT: «21»
Here, the 1 + 2 * 3 !! 4
is parsed as 1 + ((2 * 3) !! 4)
, because the precedence of the new !!
operator is between that of +
and *
.
The same effect could have been achieved with:
sub infix:<!!>(, ) is looser(:<*>)
To put a new operator on the same precedence level as an existing operator, use is equiv(&other-operator)
instead.