Fork me on GitHub
#unrepl
<
2017-05-13
>
richiardiandrea15:05:50

@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...

cgrand15:05:18

@richiardiandrea it's print.clj the key namespace to port.

richiardiandrea15:05:22

Kk I will have a look there...anything I need to be aware of?

cgrand15:05:59

It depends on a couple of dynamic vars which are defined in unrepl.core

cgrand15:05:45

So you will have to stub or port them.

richiardiandrea16:05:11

Got it, yeah dynamic vars in cljs - no good 😀

cgrand16:05:10

The bindings last only the time to print the value. No callback, no laziness. Should be safe.

richiardiandrea16:05:12

Well in any case it is single threaded

cgrand17:05:33

One thread does not equate one logical process.

richiardiandrea17:05:08

Uhm I don't understand the connection to binding of the above statement

richiardiandrea17:05:37

Dynamic vars are not casting process boundaries anyways right?

pesterhazy17:05:34

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

richiardiandrea17:05:24

Oh ok yes that's​ right , thank you sorry for misunderstanding 😀

dominicm18:05:21

binding works more like with-redefs in cljs vs clj then? 😞

dominicm18:05:36

Oh, same problem in clj. Need to go look into this :thinking_face:

anmonteiro18:05:57

I don’t think Clojure suffers from the same issue

anmonteiro18:05:10

even if it does you can get around it with bound-fn

dominicm18:05:07

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

anmonteiro18:05:26

sure, because bindings are thread local

dominicm18:05:57

@anmonteiro I don't understand really, futures are a separate thread. I thought bindings were "forking" by some description.

anmonteiro18:05:34

@dominicm

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

dominicm18:05:22

ah, so future is a special case then really?

anmonteiro18:05:34

yeah, future clones the bindings in place

dominicm18:05:41

Got it, and no bound-fn in clojurescript it seems. https://github.com/binaryage/cljs-zones somebody is on it.

anmonteiro18:05:46

yeah, there has been some discussion in #cljs-dev about it before

anmonteiro18:05:11

IIRC the last discussion was started by Cristophe who was looking for an old bound-fn proposal

cgrand12:05:15

@anmonteiro I'm still working on a new proposal but bound-fn is the wrong solution for cljs

richiardiandrea18:05:49

Yeah that bound-fn issue for cljs is very old...Prolly using cljs-zones is the quickest for now

richiardiandrea18:05:01

Didn't know that future was special thanks for sharing !

richiardiandrea19:05:30

newborn-zone is epic ahah. Interesting that every async trick in js ends up being code transformation and functions basically

cgrand12:05:15

@anmonteiro I'm still working on a new proposal but bound-fn is the wrong solution for cljs