Skip to content

Instantly share code, notes, and snippets.

@hlship
Created August 19, 2014 20:16
Show Gist options
  • Save hlship/45fd7695a30740bcf0ca to your computer and use it in GitHub Desktop.
Save hlship/45fd7695a30740bcf0ca to your computer and use it in GitHub Desktop.
Implementation of cond-let macro
(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