Created
August 19, 2014 20:16
-
-
Save hlship/45fd7695a30740bcf0ca to your computer and use it in GitHub Desktop.
Implementation of cond-let macro
This file contains hidden or 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
(defmacro cond-let | |
"A merging of cond and let. Each term is either a vector | |
(in which case, it acts like let) or a condition expression followed by the value | |
for that expression. An empty cond-let returns nil." | |
[& forms] | |
(when forms | |
(if (vector? (first forms)) | |
`(let ~(first forms) | |
(cond-let ~@(rest forms))) | |
(if-not (next forms) | |
(throw (IllegalArgumentException. "cond-let requires a result form to follow each test form")) | |
`(if ~(first forms) | |
~(second forms) | |
(cond-let ~@(drop 2 forms))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment