Course of Raku / Advanced / Operators / User-defined operators
Quiz — Defining an operator
What does the following program print?
sub infix:<times>($a, $b) { $a * $b }
say 6 times 7;| 1 | 42 |
| 0 | 67 |
| 0 | times |
| 0 | an error |
infix:<times> defines a new operator written
between its two operands. Its body multiplies them, so
6 times 7 evaluates to 42 — an operator is
just a subroutine with a special name.