According to the Clojure documentation:
The bindings are sequential, so each binding can see the prior bindings.
Are you a Lisp or Scheme programmer? Clojure let
is like let*
in CL or Scheme in this regard.
سؤال
I am working through an example of destructuring in the Joy of Clojure, and I cam across an example that surprised me. Both of these produce the same output:
(let [range-vec (vec (range 10)) [a b c & more :as all] range-vec]
(println "a b c: " a b c)
(println "more: " more)
(println "all: " all))
(let [range-vec (vec (range 10))]
(let [[a b c & more :as all] range-vec]
(println "a b c: " a b c)
(println "more: " more)
(println "all: " all)))
Now initially the first form countered my intuition because, thinking that binding and precedence happened from left to right, that range-vec would not be defined before assigning to "all". I the second form, range-vec has already been defined, and then assigned to all in the second let statement, which seems to follow the rules I know so far. When do I know when a symbol has been bound and the order in which that happens?
المحلول
According to the Clojure documentation:
The bindings are sequential, so each binding can see the prior bindings.
Are you a Lisp or Scheme programmer? Clojure let
is like let*
in CL or Scheme in this regard.