Skip to content

Instantly share code, notes, and snippets.

@daviddavis
Created April 26, 2011 21:47
Show Gist options
  • Save daviddavis/943255 to your computer and use it in GitHub Desktop.
Save daviddavis/943255 to your computer and use it in GitHub Desktop.
Implementing my own reverse
;; Exception in thread "main" java.lang.UnsupportedOperationException: Can only recur from tail position (test.clj:6)
(defn rev [data]
(loop [data data, product ()]
(if (empty? data)
product
((conj product (first data))
(recur (rest data) product)))))
(print (rev '(1 2 3 4 5)))
;; loops endlessly
(defn rev [data]
(loop [data data, product ()]
(if (empty? data)
product
(conj product (first data)))
(recur (rest data) product)))
(print (rev '(1 2 3 4 5)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment