In Raku, infix operators can be used like functions, e.g.:
1 + 2 ; # 3
infix:<+>(1, 2) ; # 3
[+] 1, 2 ; # 3
Prefix operators can be used with method-like syntax (methodop):
-1 ; # -1
1.:<-> ; # -1
So, (rather academic) question is, can infix operators also be used in method-like way, like 1.:<+>(2)
(which is wrong) ?
(1 + *)(2) ; # 3
… that's function (sort of) definition and call, not a method call, nor method-like syntax.
my method plus(Int $b --> Int){
return self + $b;
}
1.&plus(2) ; # 3
… but +
name cannot be used, also that's not direct operator usage without an additional function definition.
However, for operators built in to Raku, all operators with the same precedence level also have the same associativity. Setting the associativity of non-infix operators is not yet implemented. In the operator descriptions below, a default associativity of leftis assumed. Operator classification
An operator in prefix form can still be called like a method, that is, using the .methodop notation, by preceding it by a colon. For example: my $a = 1; say ++$a; # OUTPUT: «2» say $a.:<++>; # OUTPUT: «3» Technically, not a real operator; it's syntax special-cased in the compiler, that is why it's classified as a methodop. methodop .::
These operators are like their Method Postfix counterparts, but require surrounding whitespace (before and/or after) to distinguish them. infix .= Calls the right-side method on the value in the left-side container, replacing the resulting value in the left-side container.
2 shr 1 + 2 and 2 shr (1 + 2) 1 until n * 2 and 0 until (n * 2) xs union ys as Set<*> and xs union (ys as Set<*>) On the other hand, infix function call have higher precedence than the boolean operators && and ||, is- and in-checks, and some other operators.
You can use
1.&infix:<+>(2)
1.&[+](2)
1.&(*+*)(2)
1.&{$^a +$^b}(2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With