Fork me on GitHub
#cljs-dev
<
2019-09-08
>
richiardiandrea20:09:12

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

richiardiandrea20:09:33

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?

richiardiandrea20:09:45

Otherwise the repl input I am running on will get captured from the new Java process (it seems)

potetm22:09:56

@richiardiandrea You can use :special-fns as a repl option

potetm22:09:28

so you can pass a special fn that prints env

potetm22:09:17

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.

richiardiandrea15:09:24

I cannot see the :special-fns options in the repl?

potetm01:09:01

It’s not document iirc

richiardiandrea16:09:25

sorry to beat this horse but I have finally tried 😄

user=> env
#cljs.repl.nashorn.NashornEnv{:engine #object[jdk.nashorn.api.scripting.NashornScriptEngine 0x77719e74 "[email protected]"], :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?

richiardiandrea16:09:09

no well, it is clj code after all ... I think I am still missing something

potetm18:09:05

I can’t see what test-me does 🙂

potetm18:09:00

you can see how they’re used and how special fns are implemented

richiardiandrea19:09:12

it does (prn form) 😄

richiardiandrea00:09:13

Ok I got it, I was passing the :special-fns key to the nashorn env, not the inner cljs env

richiardiandrea00:09:40

cljs.user=> (test-fn (+ 1 2))
******
(test-fn (+ 1 2))
******
👍

aw_yeah 4
richiardiandrea22:09:41

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

richiardiandrea22:09:46

(that's why I thought I could exec that in a separate thread, but maybe I am on the wrong track here)

potetm22:09:54

(my-special-fn (run-some-code)) where {'my-special-fn (fn[_ _ form] (prn (form)))} might actually work?

potetm22:09:16

alternatively, you might even be able to launch a new repl in a special fn?

potetm22:09:50

you basically get full control in special fns — you can talk to the server, you can inspect the client env

richiardiandrea22:09:04

Oh I see will try that, thanks!