clojure.core/let¶
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¶
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¶
- clojure.core/letfn (1)
- clojure.core/if-let (7)
- clojure.core/fn (3)
- clojure.core/for (14)
Content from the matching ClojureDocs page, with authors credited on each contribution.