From 42d31a20bae370d2b99cb30516e6c06bb67b5f72 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Wed, 15 May 2019 00:56:50 +0200 Subject: [PATCH] exercises: recommend not to override nth permanently --- docs/exercises.md | 4 ++++ examples/exercises.mal | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/exercises.md b/docs/exercises.md index dddad9c8..aac6eb6c 100644 --- a/docs/exercises.md +++ b/docs/exercises.md @@ -52,6 +52,10 @@ make REGRESS=1 TEST_OPTS='--hard --pre-eval=\(load-file\ \"../answer.mal\"\)' te 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. diff --git a/examples/exercises.mal b/examples/exercises.mal index be51eb6d..247e0506 100644 --- a/examples/exercises.mal +++ b/examples/exercises.mal @@ -23,13 +23,13 @@ (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))]