4.9 Higher Order Functions
TBoS p.84-85, SD
Higher order functions are supported. When passing a symbol denoting a function as an argument to a
higher order function it is necessary to use 'fn' to indicate that the symbol is denoting a function.
(0-) (define foldl
F Z [] -> Z
F Z [X | Xs] -> (foldl F (F Z X) Xs))
(fn foldl)
(1-) (foldl (fn +) 0 [1 2 3])
6
(2-) (map (+ 1) [1 2 3 4])
[2 3 4 5]
(3-) (map (/. X (- X 1)) [1 2 3 4])
[0 1 2 3] |
|