nrepl/piggieback

How to change the value of a cljs Var for an eval op?

Malabarba opened this issue · 3 comments

Hi there. I'm trying to port the cider debugger to cljs, and there's one obstacle I've encountered related to piggieback.

With regular clojure and the nrepl, I could specify a variable value for the eval op by using the session atom. For instance, in this line we add couple of reader macros to the message's #'*data-readers* binding, and this binding will be in effect when the message finally reaches the interruptible-eval middleware.

Now I need to do something very similar for when the user is running clojurescript. I need to ensure that, when the eval message reaches piggieback to be evaluated, the cljs.reader/*tag-table* variable is bound to a value I specify.

Is there a proper way to do that?
Please let me know if I'm not being clear enough.

cljs.reader is a ClojureScript namespace, and so its value only ever exists in the JavaScript runtime. In contrast, nREPL sessions are only related to the Clojure dynamic environment. So, the former cannot be affected by manipulating the latter.

What you probably want to do is wrap the expression to be evaluated with a binding form that temporarily establishes the *tag-table* you need.

Thanks. Indeed, the fact that I'm dealing with a cljs namespace is part of the problem. Thanks for the answer.

The issue with binding the value around the expression is that this binding will not be in effect when the expression is read, only when its evaluated. I need this value to be in effect when the expression is read. (Sorry, I really wasn't clear about that in the first comment.)

However, I've been playing around some more, and I think it'll be enough to set this value permanently when the repl is first created (instead of binding it around each expression). I'll come back if I have more problems. :-)

Thanks for you help!

Are you sure about the read-time constraint? cljs.reader is only relevant when reading in ClojureScript, e.g. using read-string and so on. ClojureScript you send for evaluation is read and compiled in Clojure, and so cljs.reader isn't available at all; I think you want to be fiddling with the read table in tools.reader instead:

https://github.com/clojure/tools.reader/blob/master/src/main/clojure/clojure/tools/reader.clj#L35

…in which case manipulating the nREPL session remains a reasonable approach: