Fork me on GitHub
#cljs-dev
<
2018-02-21
>
mfikes00:02:20

ClojureScript appears to not do bindings in parallel (as indicated in the docstring for binding). True? Is the fact that the last form evaluates to 3 instead of 2 a bug?

cljs.user=> (def ^:dynamic *a* 1)
#'cljs.user/*a*
cljs.user=> (def ^:dynamic *b* nil)
#'cljs.user/*b*
cljs.user=> (binding [*a* 2 *b* (inc *a*)] *b*)
3

dnolen01:02:26

Does that specific example work in Clojure? I didn’t think it did?

mfikes02:02:50

In Clojure (binding [*a* 2 *b* (inc *a*)] *b*) evaluates to 2. This follows the docstring portion indicating "all init-exprs are evaluated before the vars are bound to their new values" (my emphasis added)

mfikes03:02:21

Interestingly, if you check out https://dev.clojure.org/jira/browse/CLJ-152 and the mailing list link posted, you unfortunately don't get an answer as to why bindings are done in parallel. Perhaps it makes it easier to atomically unwind all bindings if done this way? Anyway, the rationale is no longer important; I guess we just have to accept that parallel binding is the Clojure behavior.

john14:02:06

@dnolen well that's a relief 🙂

john14:02:40

Well, there's self-host...

bronsa14:02:12

@mfikes the superficial reason as to why they are done in parallel in clojure is that binding is just a macro over push-thread-bindings and that accepts a map of bindings, so sequentiality is thrown out of the window

bronsa15:02:01

as to the design decision for going with a map, no idea about that

mfikes15:02:07

@bronsa Yeah, I was thinking along those lines as well. Makes sense.