2017-04-16 14:18:52 +00:00
|
|
|
def inc (fn [x] (+ x 1))
|
2017-04-17 15:35:28 +00:00
|
|
|
def map (fn [f lst]
|
|
|
|
(if (empty? lst)
|
|
|
|
[]
|
|
|
|
(cons (f (first lst))
|
|
|
|
(map f (rest lst)))))
|
|
|
|
def test (fn [name expr]
|
|
|
|
(if expr
|
|
|
|
(prn (str name " OK"))
|
|
|
|
(prn (str name " FAILED"))))
|
2017-04-16 14:18:52 +00:00
|
|
|
test "map" (= [2 3 4] (map inc [1 2 3]))
|
|
|
|
test "double map" (= [3 4 5] (map inc (map inc [1 2 3])))
|