Created
March 18, 2011 08:13
-
-
Save amalloy/875767 to your computer and use it in GitHub Desktop.
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
Which do you like better? Will the second have issues if the user has an unusual ns declaration, in which clojure.core/cond is not mapped? | |
(defmacro cond [& clauses] | |
(if-not (even? (count clauses)) | |
(throw (IllegalArgumentException. "cond requires an even number of forms")) | |
(reduce (fn [else [test then]] | |
`(if ~test ~then ~else)) | |
nil | |
(reverse (partition 2 clauses))))) | |
(defmacro cond [& clauses] | |
(when clauses | |
(list 'if (first clauses) | |
(if (next clauses) | |
(second clauses) | |
(throw (IllegalArgumentException. | |
"cond requires an even number of forms"))) | |
(cons 'clojure.core/cond (next (next clauses)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment