10

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) ?

Currying

(1 + *)(2) ;     # 3

… that's function (sort of) definition and call, not a method call, nor method-like syntax.

Custom method

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.

mykhal
  • 19,175
  • 11
  • 72
  • 80

1 Answers1

13

You can use

1.&infix:<+>(2)
1.&[+](2)

1.&(*+*)(2)
1.&{$^a +$^b}(2)
wamba
  • 3,883
  • 15
  • 21