arcadia-unity / ArcadiaGodot

Other
178 stars 14 forks source link

Evaluating ns form in REPL doesn't work #20

Closed kwrooijen closed 3 years ago

kwrooijen commented 3 years ago

When connecting to the REPL using Cider and evaluating (ns main.game) I'm getting the following error:

System.InvalidOperationException: Can't change/establish root binding of: *ns* with set
  at clojure.lang.Var.set (System.Object val) [0x00054] in <fb1204dbf0b848beaab1559f81f1b22c>:0 
  at clojure.lang.RT+InNamespaceFn.invoke (System.Object arg1) [0x0000c] in <fb1204dbf0b848beaab1559f81f1b22c>:0 
  at clojure$core$eval__2098__2103.invokeStatic () [0x0000a] in <b0b43980684441d591a9eb2065c7c9df>:0 
  at clojure$core$eval__2098__2103.invoke () [0x00000] in <b0b43980684441d591a9eb2065c7c9df>:0 
  at clojure.lang.Compiler.eval (System.Object form) [0x001c2] in <fb1204dbf0b848beaab1559f81f1b22c>:0 
  at clojure.lang.Compiler.eval (System.Object form) [0x0012a] in <fb1204dbf0b848beaab1559f81f1b22c>:0 
  at clojure$core$eval__22334.invokeStatic (System.Object ) [0x00000] in <75aedcbf6ad14e4293bea1888c10ab1d>:0 
  at clojure$core$eval__22334.invoke (System.Object ) [0x00000] in <75aedcbf6ad14e4293bea1888c10ab1d>:0 
  at arcadia$repl$main_thread_evalfn__547__551.invoke () [0x0000a] in <b0b43980684441d591a9eb2065c7c9df>:0 
  at AdhocSignals.CatchMethod (System.String hash) [0x00002] in /home/kwrooijen/Programming/Godot/godot-mono-test/ArcadiaGodot/Source/AdhocSignals.cs:36
kwrooijen commented 3 years ago

Found the issue. The NRepl.cs evaluator calls arcadia.repl/main-thread-eval. Which in turn calls (main-thread (fn [] (eval s))). When replacing this with simply (eval s) the issue disappears. Also my evaluations are now inside of my editor (that being Emacs) instead of in the terminal where I opened Godot, which is also a big plus in development.

The main-thread function does have the following comment though: ;; hack to have tooling eval on main thread (as instancing some node types on a thread is currently very slow)

I'm honestly not sure what this means. Maybe you can clarify the purpose? For now I'm going to disable it locally until I run into issues.

selfsame commented 3 years ago

the main thread eval was a workaround for https://github.com/arcadia-unity/ArcadiaGodot/issues/14 but yes looks like it broke the Nrepl, will investigate!

selfsame commented 3 years ago

yeah this is tricky, the ns error is a thing that happens when you don't bind an initial namespace (see https://clojuredocs.org/clojure.core/*ns*#example-59468a29e4b06e730307db35) but apart from fixing that the async main-thread-eval would have to get it's results back into the NRepl's loop somehow.

Since none of that was trivial I've reverted main thread eval for NRepl.cs in 55fc5c5ed7ad1074d41ab6536feead8ee894368f

I'll close this and re-open #14