Try to replace explicit recursions with calls to `reduce` and `foldr`.
+ Once you have tested your solution, you should comment at least
+ `nth`. Many implementations, for example `foldr` in `core.mal`,
+ rely on an efficient `nth` built-in function.
+
- Implement the `do` special as a non-recursive function. The special
form will hide your implementation, so in order to test it, you will
need to give it another name and adapt the test accordingly.
(def! count
(let* [inc_left (fn* [acc _] (inc acc))]
(fn* [xs] (if (nil? xs) 0 (reduce inc_left 0 xs)))))
-(def! nth
- (fn* [xs index]
- (if (or (empty? xs) (< index 0))
- (throw "nth: index out of range")
- (if (zero? index)
- (first xs)
- (nth (rest xs) (dec index))))))
+;; (def! nth
+;; (fn* [xs index]
+;; (if (or (empty? xs) (< index 0))
+;; (throw "nth: index out of range")
+;; (if (zero? index)
+;; (first xs)
+;; (nth (rest xs) (dec index))))))
(def! map
(fn* [f xs]
(let* [iter (fn* [x acc] (cons (f x) acc))]