Created
April 26, 2011 21:47
-
-
Save daviddavis/943255 to your computer and use it in GitHub Desktop.
Implementing my own reverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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