Skip to content

Iteration — array methods + recursion

Quilon has no for/while loop. A collection is iterated with the built-in array methods: .each runs a body for its side effects (the direct replacement for a side-effecting loop), and .map/.filter/.reduce transform or fold without any mutable accumulator. Each takes a lambda, applied per element:

nums = [1, 2, 3]
nums.each(n => print(n)) ~ side effects; returns the receiver (chainable)
sum = nums
.map(n => n * 2) ~ [2, 4, 6]
.reduce(0, (acc, n) => acc + n) ~ 12

When iteration doesn’t fit a method, use recursion: a self-tail-call is guaranteed to run in constant stack, so even deep recursion is safe. (See examples/iteration.qn.)