cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
richiardiandrea 2019-09-08T20:07:12.051500Z

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

richiardiandrea 2019-09-08T20:08:33.053500Z

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?

richiardiandrea 2019-09-08T20:12:45.053900Z

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

2019-09-08T22:10:56.054500Z

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

2019-09-08T22:12:28.055700Z

so you can pass a special fn that prints env

2019-09-08T22:16:17.058200Z

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.

richiardiandrea 2019-09-09T15:38:24.063700Z

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

2019-09-10T01:46:01.084200Z

Itโ€™s not document iirc

richiardiandrea 2019-09-16T16:41:25.008700Z

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?

richiardiandrea 2019-09-16T16:46:09.008900Z

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

2019-09-16T18:05:05.025300Z

I canโ€™t see what test-me does ๐Ÿ™‚

2019-09-16T18:07:40.025500Z

take a look here: https://github.com/potetm/tire-iron

2019-09-16T18:08:00.025800Z

you can see how theyโ€™re used and how special fns are implemented

richiardiandrea 2019-09-16T19:52:12.027500Z

it does (prn form) ๐Ÿ˜„

richiardiandrea 2019-09-16T19:52:22.027700Z

ok checking!

richiardiandrea 2019-09-17T00:11:13.028100Z

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

richiardiandrea 2019-09-17T00:14:40.028400Z

cljs.user=> (test-fn (+ 1 2))
******
(test-fn (+ 1 2))
******
๐Ÿ‘

1
richiardiandrea 2019-09-08T22:16:41.059Z

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

richiardiandrea 2019-09-08T22:17:46.060500Z

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

2019-09-08T22:19:54.062Z

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

2019-09-08T22:20:16.062500Z

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

2019-09-08T22:20:50.063300Z

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

richiardiandrea 2019-09-08T22:21:04.063500Z

Oh I see will try that, thanks!