Higher Order FunctionsΒΆ

Shen supports higher-order functions. In all ports of Shen running under variants of Lisp, the above will work.

(0-) (define foldl
       F Z [] -> Z
       F Z [X | Xs] -> (foldl F (F Z X) Xs))
foldl

(1-) (foldl (function +) 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]

Under non-Lisp platforms, where Lisp symbols are not supported, it is wise to use ‘function’ to indicate that a symbol is being used as an argument to denote a function

Further Reading