Course of Raku / Advanced / Operators / User-defined operators / Exercises

A squaring operator

Problem

An operator’s symbol can be any character, including a Unicode one. Define a postfix operator ² that squares its operand, so that 5² means 5 ** 2. Then print 5².

Example

The program prints:

25

Solution

✅ See the solution

Course navigation

← Solution: Percent-of operator   |   Solution: A squaring operator →