macro | since v0.0-927 | imported clojure.core/if-let | Edit |
(if-let bindings then)
(if-let bindings then else & oldform)
When test
is logical true, evaluates then
with the value of test
bound to
x
. Otherwise, evaluates else
with no bindings.
else
defaults to nil.
bindings => binding-form test If test is true, evaluates then with binding-form bound to the value of test, if not, yields else
(defmacro if-let
{:added "1.0"}
([bindings then]
`(if-let ~bindings ~then nil))
([bindings then else & oldform]
(assert-args
(vector? bindings) "a vector for its binding"
(nil? oldform) "1 or 2 forms after binding vector"
(= 2 (count bindings)) "exactly 2 forms in binding vector")
(let [form (bindings 0) tst (bindings 1)]
`(let [temp# ~tst]
(if temp#
(let [~form temp#]
~then)
~else)))))