A bit rusty here as I am working on the a cider issue Say I create a Rhino REPL with the instructions https://clojurescript.org/reference/repl
Is there a neat one liner to get the control back to the caller? Meaning, I want to inspect the env
, what should I do? Is running (repl/repl env)
in a future
an option?
Otherwise the repl input I am running on will get captured from the new Java process (it seems)
@richiardiandrea You can use :special-fns
as a repl option
they receive env
as a param when invoked: https://github.com/clojure/clojurescript/blob/b38ded99dc0967a48824d55ea644bee86b4eae5b/src/main/clojure/cljs/repl.cljc#L783-L788
so you can pass a special fn that prints env
You can do a lot w/ :special-fns
actually. Itโs run on the client-side (i.e. w/ the compiler), so you can do all kinds of work there.
I cannot see the :special-fns
options in the repl?
Itโs not document iirc
You can see it takes it here: https://github.com/clojure/clojurescript/blob/b38ded99dc0967a48824d55ea644bee86b4eae5b/src/main/clojure/cljs/repl.cljc#L1062 And it uses it here: https://github.com/clojure/clojurescript/blob/b38ded99dc0967a48824d55ea644bee86b4eae5b/src/main/clojure/cljs/repl.cljc#L1115
sorry to beat this horse but I have finally tried ๐
user=> env
#cljs.repl.nashorn.NashornEnv{:engine #object[jdk.nashorn.api.scripting.NashornScriptEngine 0x77719e74 "jdk.nashorn.api.scripting.NashornScriptEngine@77719e74"], :debug nil, :special-fns {test-me #function[user/fn--6454]}}
user=> (cider.piggieback/cljs-repl env)
To quit, type: :cljs/quit
nil
cljs.user=> (test-me)
WARNING: Use of undeclared Var cljs.user/test-me at line 1 <cljs repl>
So I am still missing something it seems, maybe the special fn is a form, not a function object?no well, it is clj code after all ... I think I am still missing something
I canโt see what test-me
does ๐
take a look here: https://github.com/potetm/tire-iron
you can see how theyโre used and how special fns are implemented
it does (prn form)
๐
ok checking!
Ok I got it, I was passing the :special-fns
key to the nashorn env, not the inner cljs env
cljs.user=> (test-fn (+ 1 2))
******
(test-fn (+ 1 2))
******
๐Oh ok, well, my problem is that the input is now listening for things for the Cljs repl instead, but I want to eval clj code
(that's why I thought I could exec that in a separate thread, but maybe I am on the wrong track here)
(my-special-fn (run-some-code))
where {'my-special-fn (fn[_ _ form] (prn (form)))}
might actually work?
alternatively, you might even be able to launch a new repl in a special fn?
you basically get full control in special fns โ you can talk to the server, you can inspect the client env
Oh I see will try that, thanks!