Skip to content

clojure.core/let

View this page on ClojureDocs

Type: macro Added: Clojure 1.0 Examples: 11 Runnable: 7
([bindings & body])

binding => binding-form init-expr binding-form => name, or destructuring-form destructuring-form => map-destructure-form, or seq-destructure-form

Evaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respective init-exprs or parts therein.

See https://clojure.org/reference/special_forms#binding-forms for more information about destructuring.

Examples

by zk on . May have evaluation errors.
by nipra on . May have evaluation errors.
by johnfn on . May have evaluation errors.
by leifp on
by ryo on
by phreed on
by freezhan on
by ibercode on . May have evaluation errors.
by funkrider on
by rgkirch on
by jimka2001 on

Note by TimMc

Nota Bene: let in Clojure is like let* in Scheme -- each init-expr has access to the preceding binding forms. (There is also a let*, but it is more or less let without destructuring, and in fact is the underlying implementation.)

Note by bfontaine

Be aware that let’s :or always evaluates the default value, unlike the or macro:

user=> (let [{:keys [a]
              :or {a (do (println "toto") 1)}} {}]
         a)
toto
1

user=> (let [{:keys [a]
              :or {a (do (println "toto") 1)}} {:a 2}]
         a)
toto
2

See also


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