Created
October 4, 2013 14:21
-
-
Save gilbertw1/6826716 to your computer and use it in GitHub Desktop.
Versions of if-let and when-let which take any number of test bindings.
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
(defn recursive-when-let [[[form tst] & othrs] body] | |
`(let [temp# ~tst] | |
(when temp# | |
(let [~form temp#] | |
~@(if (nil? othrs) | |
body | |
`(~(recursive-when-let othrs body))))))) | |
(defmacro when-let* [bindings & body] | |
(recursive-when-let (partition 2 bindings) body)) | |
(defn recursive-if-let [[[form tst] & othrs] if-body else-body] | |
`(let [temp# ~tst] | |
(if temp# | |
(let [~form temp#] | |
~(if (nil? othrs) | |
if-body | |
(recursive-if-let othrs if-body else-body))) | |
~else-body))) | |
(defmacro if-let* [bindings if-body else-body] | |
(recursive-if-let (partition 2 bindings) if-body else-body)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment