Created
June 18, 2011 20:13
-
-
Save cgrand/1033467 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
(defmacro if-let | |
"A variation on if-let where all the exprs in the bindings vector must be true and also supports :let." | |
([bindings then] | |
`(if-let ~bindings ~then nil)) | |
([bindings then else] | |
(if (seq bindings) | |
(if (= :let (bindings 0)) | |
`(let ~(bindings 1) | |
(if-let ~(subvec bindings 2) ~then ~else)) | |
`(let [test# ~(bindings 1)] | |
(if test# | |
(let [~(bindings 0) test#] | |
(if-let ~(subvec bindings 2) ~then ~else))))) | |
then))) | |
(defmacro when-let | |
"A variation on when-let where all the exprs in the bindings vector must be true and also supports :let." | |
[bindings & body] | |
`(if-let ~bindings (do ~@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment