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;
142
067
0times
0an 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.

Course navigation

Solution: A squaring operator   |   Traits and pragmas 🆕