Skip to content

Instantly share code, notes, and snippets.

@gilbertw1
Created October 4, 2013 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilbertw1/6826716 to your computer and use it in GitHub Desktop.
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.
(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