On Lisp – chapter 3

19 12 2009

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)
      (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))



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: