You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
562 B
22 lines
562 B
(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)))
|
|
|