Chapter 3 is a small chapter, it really talks about the wrong way to do things in Common Lisp.
;; Clojure is not the best Lisp dialect to implement
;; bad reverse. In fact its rather painful. While the
;; bad reverse example is great for what you
;; shouldn't do, i'd rather port the good ones.
;; page 30
(defn good-reverse [lst]
(loop [lst lst acc '()]
(if (empty? lst)
acc
(recur (rest lst) (conj acc (first lst))))))
;; Clojure does not support multiple return values,
;; however it does support destructuring
;; page 32
(defn powers [x]
[x (Math/pow x 2)])
(let [[base square] (powers 4)]
(list base square))
Advertisement