unrepl

discussing specification of an edn-based repl and its implementations.
cgrand 2017-05-15T07:52:30.079028Z

@dominicm on why I consider bound-fn unfit?

dominicm 2017-05-15T07:54:24.102624Z

@cgrand mmhm, and what you think more suitable.

cgrand 2017-05-15T08:01:48.201669Z

JS being single threaded doesn’t mean you can’t have several logical processes (cooperatively) sharing the thread. In many cases the callback you pass is the continuation of the current process. On the JVM this style is infrequent because there are preemptive threads. So bound-fn is ok for the occasional call. In js you wouljd litter your code with bound-fn calls. Furthermore bound-fn flattens the dynamic bindings stack. Which makes impossible some continuation stuff. E.g. in Clojure (with-open [f ...] (do sync IO)) can’t be translated to (with-open [f ..] (.on f "data" (bound-fn ...))) because resource reclamation must happen in the continuation (otherwise by the time the callback is called the resource is already disposed.

cgrand 2017-05-15T08:03:17.222684Z

Basically I think the callback-as-continuation scenario needs special support for dynamic variables and for the other dynamically scoped feature: try/catch/finally

dominicm 2017-05-15T12:40:04.983006Z

I see, interesting. A difficult thing to achieve though! Although very simple if we were to generate ES.next code (with the new async functions)

pesterhazy 2017-05-15T14:26:32.214587Z

could you explain how that would help @dominicm ?

dominicm 2017-05-15T15:01:47.097803Z

@pesterhazy my understanding is that try/catch works with e.g. async/await

dominicm 2017-05-15T15:01:54.100521Z

That might be wrong though now I think about it

dominicm 2017-05-15T15:03:06.132200Z

https://pouchdb.com/2015/03/05/taming-the-async-beast-with-es7.html yes, yes you can

richiardiandrea 2017-05-15T16:07:41.726811Z

Isn't the continuation approach exactly what cljs-zones does?

richiardiandrea 2017-05-15T16:08:10.738277Z

I might have misread it from the Klipse example above

richiardiandrea 2017-05-15T16:10:45.796616Z

Reading as we speak πŸ˜€

cgrand 2017-05-15T19:00:09.574603Z

I wouldn't say exactly. Plus I believe the prototype-based implementation is flawed: a set on a dynamic var bound in an outer scope should survive to the current scope

richiardiandrea 2017-05-15T19:15:32.896853Z

@cgrand I think that is exactly the point of using prototypes, but I am not a JS master so maybe we can summon @darwin to this channel πŸ˜„

cgrand 2017-05-15T19:23:46.063727Z

@richiardiandrea (binding [a 1] (binding [b 2] (set! a 3)) a) should evaluate to 3 not to 1.

richiardiandrea 2017-05-15T19:25:01.089522Z

returns 3

richiardiandrea 2017-05-15T19:25:10.092982Z

no sorry πŸ˜„

richiardiandrea 2017-05-15T19:25:49.106283Z

(ns zones.test
  (:require [zones.core :as zones :include-macros true]))

(zones/binding [a 1] (zones/binding [b 2] (set! a 3)) a)

richiardiandrea 2017-05-15T19:25:57.109020Z

this evaluates to 3

richiardiandrea 2017-05-15T19:26:47.125649Z

again, not the author here, but prototypes inherit properties so this can go as deep as needed...

richiardiandrea 2017-05-15T19:28:49.167023Z

there are also a bunch of tests: https://github.com/binaryage/cljs-zones/blob/master/test/src/tests/zones/tests/core.cljs#L97

cgrand 2017-05-15T19:31:04.213575Z

And if you replace set! by zone/set! And plain a by (zone/get a) β€” sorry to use you as a repl but I only have two thumbs

richiardiandrea 2017-05-15T19:31:16.217422Z

np let me check πŸ˜„

richiardiandrea 2017-05-15T19:32:10.235145Z

(ns zones.test
  (:require [zones.core :as zones :include-macros true]))

(zones/binding [a 1] (zones/binding [b 2] (zones/set! a 3)) (zones/get a))
=> 3

richiardiandrea 2017-05-15T19:32:59.251670Z

no zones/get is the same

(ns zones.test
  (:require [zones.core :as zones :include-macros true]))

(zones/binding [a 1] (zones/binding [b 2] (zones/set! a 3)) a)
...this one does not work as expected actually... so you need a zones/get

richiardiandrea 2017-05-15T19:33:25.260418Z

I like, it is good to see if we can break it πŸ˜‰

cgrand 2017-05-15T19:35:13.297153Z

Hmm I'll have to look at the impl because the prototype chain only works for getting a property. All sets are shallow.

πŸ‘ 1
cgrand 2017-05-15T20:21:15.238567Z

So the protochain is explicitly walked. Would be interesting to benchmark as this kind of behavior used to trigger perf penalties (because of cache invalidation).

πŸ‘ 1