@cgrand how far are you from a cljs unrepl? And how can I contribute to it? I saw once one namespace to port to cljs...
@richiardiandrea it's print.clj the key namespace to port.
Kk I will have a look there...anything I need to be aware of?
It depends on a couple of dynamic vars which are defined in unrepl.core
So you will have to stub or port them.
Got it, yeah dynamic vars in cljs - no good π
The bindings last only the time to print the value. No callback, no laziness. Should be safe.
Well in any case it is single threaded
One thread does not equate one logical process.
Uhm I don't understand the connection to binding
of the above statement
Dynamic vars are not casting process boundaries anyways right?
I think christophe means this:
cljs.user=> (def ^:dynamic x :foo)
#'cljs.user/x
cljs.user=> (binding [x :bar] (prn x))
:bar
nil
cljs.user=> (binding [x :bar] (js/setTimeout #(prn x)))
#object[Timeout [object Object]]
cljs.user=> :foo
Oh ok yes that'sβ right , thank you sorry for misunderstanding π
binding
works more like with-redefs
in cljs vs clj then? π
Oh, same problem in clj. Need to go look into this :thinking_face:
I donβt think Clojure suffers from the same issue
even if it does you can get around it with bound-fn
http://blog.cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots works with futures. But this isn't quite what I expect:
user=> (binding [*x* :bound] (.start (Thread. (fn [] (Thread/sleep 10) (prn *x*)))))
nil
:initial
user=> (.start (Thread. (binding [*x* :bound] (fn [] (Thread/sleep 10) (prn *x*)))))
nil
:initial
sure, because bindings are thread local
@anmonteiro I don't understand really, futures are a separate thread. I thought bindings were "forking" by some description.
boot.user=> (binding [*x* :bound] (.start (Thread. (fn [] (Thread/sleep 10) (prn *x*)))))
nil
:initial
boot.user=> (binding [*x* :bound] (.start (Thread. (bound-fn [] (Thread/sleep 10) (prn *x*)))))
nil
:bound
ah, so future
is a special case then really?
yeah, future
clones the bindings in place
see https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L2012
Got it, and no bound-fn in clojurescript it seems. https://github.com/binaryage/cljs-zones somebody is on it.
yeah, there has been some discussion in #cljs-dev about it before
IIRC the last discussion was started by Cristophe who was looking for an old bound-fn proposal
Yeah that bound-fn
issue for cljs is very old...Prolly using cljs-zones is the quickest for now
Didn't know that future was special thanks for sharing !
newborn-zone
is epic ahah. Interesting that every async trick in js ends up being code transformation and functions basically