serene-simple/test.srns

23 lines
562 B
Plaintext

(def reduce
(fn (f xs initial-value)
(cond
((first xs) (reduce f (rest xs) (f initial-value (first xs))))
(true initial-value))))
(def map
(fn (f xs)
(reduce (fn (acc x) (cons acc (f x))) xs (list))))
;; Since SereneSimple only have List data structure and
;; it is effecient from the start. So the following function
;; will return (6 5 4 3 2)
(println (map (fn (x) (+ 1 x))
(list 1 2 3 4 5)))
(println
(reduce (fn (y x)
(cons y (* x x)))
(list 1 2 3 4)
(list)))