Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
22 lines (18 sloc) 335 Bytes
; P04 Find the number of elements of a list.
; Predefined function
(defn f0 [l]
(count l))
; Recursion
(defn f1 [l]
(if (seq l)
(inc (f1 (rest l)))
0))
; Tail recursion
(defn f2 [l]
(loop [it l, n 0]
(if (seq it)
(recur (rest it) (inc n))
n)))
; Folding
(defn f3 [l]
(reduce (fn [a _] (inc a)) 0 l))