(defun foldr (f i xs)
(if (null xs)
i
(f (head xs)
(foldr f i (tail xs)))))
(foldr + 0 [1 2 3]) 6
A Functional Language. An implementation of a right-fold function in ZZZZ, using a recursive definition.
Also shows how the +
operator can be passed directly into a call to foldr
as a higher-order function.
(take 5
(map (lhs ^ 2)
(range. 1 inf)))
[1 4 9 16 25]
Infinite Data. In this example, an infinite list is created with a call to range.
, generating the list [1 2 3 4 ...]
. Each element of the infinite list is squared, and the first five are extracted and returned.
The lhs
function is used to apply the second argument to a function instead of the first.