Course of Raku / Advanced / Subroutines / The Whatever star 🆕 / Exercises

An open-ended range

Problem

On its own, * means “no limit”. Use it as the endpoint of a sequence: write the even numbers as the open-ended sequence 2, 4 ... *, then take the first four of them with head. Because the sequence is unbounded, only laziness makes this safe.

Example

The program prints:

(2 4 6 8)

Solution

See the solution

Course navigation

Solution: A two-argument Whatever   |   Solution: An open-ended range