Skip to content

clojure.core/if-let

View this page on ClojureDocs

Type: macro Added: Clojure 1.0 Examples: 14 Runnable: 7
([bindings then] [bindings then else & oldform])

bindings => binding-form test

If test is true, evaluates then with binding-form bound to the value of test, if not, yields else

Examples

by nipra on . May have evaluation errors.
by kumarshantanu on . May have evaluation errors.
by MrHus on . May have evaluation errors.
by jafingerhut on
by ryo on
by mars0i on . May have evaluation errors.
by mattvvhat on . May have evaluation errors.
by ertugrulcetin on
by claresudbery on
by midnio on
by cuspymd on . May have evaluation errors.
by arlicle on
by metacritical on . May have evaluation errors.
by themustafabasit on

Note by gstamp

The difference between when-let and if-let is that when-let doesn't have an else clause and and also accepts multiple forms so you don't need to use a (do...).

Note by DerGuteMoritz

I wonder what motivates the restriction of only one binding, e.g. many Schemes implement an and-let* form which allows multiple bindings, evaluating them in order and breaking out on the first binding that evaluates to false. Can somebody shed some light on this?

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.