Problem with dynamic variables
ralcantaraperez opened this issue · 2 comments
ralcantaraperez commented
Hi. I'm having problems with dynamic variables and a script loaded by closh-zero.jar. If I do it in the REPL it runs fine. This is the script file content:
#! /usr/bin/env closh-zero.jar
(def ^:dynamic my-var "initial value")
(binding [my-var "new value"]
(println my-var))
This is the error:
Exception in thread "main" Syntax error compiling at (/tmp/./test-dynamic.clj:5:1).
at clojure.lang.Compiler.load(Compiler.java:7647)
at closh.zero.frontend.main$compiler_load_file.invokeStatic(main.clj:88)
at closh.zero.frontend.main$compiler_load_file.invoke(main.clj:83)
at closh.zero.frontend.main$load_script.invokeStatic(main.clj:104)
at closh.zero.frontend.main$load_script.invoke(main.clj:96)
at closh.zero.utils.clojure_main$script_opt.invokeStatic(clojure_main.clj:514)
at closh.zero.utils.clojure_main$script_opt.invoke(clojure_main.clj:507)
at closh.zero.utils.clojure_main$main.invokeStatic(clojure_main.clj:598)
at closh.zero.utils.clojure_main$main.doInvoke(clojure_main.clj:561)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:665)
at clojure.core$apply.invoke(core.clj:660)
at closh.zero.frontend.rebel$_main$fn__2716.invoke(rebel.clj:130)
at clojure.core$with_redefs_fn.invokeStatic(core.clj:7514)
at clojure.core$with_redefs_fn.invoke(core.clj:7498)
at closh.zero.frontend.rebel$_main.invokeStatic(rebel.clj:125)
at closh.zero.frontend.rebel$_main.doInvoke(rebel.clj:124)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at closh.zero.frontend.rebel.main(Unknown Source)
Caused by: java.lang.IllegalStateException: Can't dynamically bind non-dynamic var: user/my-var
at clojure.lang.Var.pushThreadBindings(Var.java:325)
at clojure.core$push_thread_bindings.invokeStatic(core.clj:1929)
at clojure.core$push_thread_bindings.invoke(core.clj:1913)
at user$eval143.invokeStatic(test-dynamic.clj:5)
at user$eval143.invoke(test-dynamic.clj:5)
at clojure.lang.Compiler.eval(Compiler.java:7176)
at clojure.lang.Compiler.load(Compiler.java:7635)
... 18 more
dundalek commented
Thanks for the report. It looks like the problem is with the custom reader. For example following also does not work (prints nil):
#! /usr/bin/env closh-zero.jar
(println (meta ^:dynamic {}))
I will try to look into it.
dundalek commented
This is now fixed in master.
I would like to fix some more bugs and release a new version after that. In the meantime you use manual build. Clone the repo, run npm run pkg-java
and you will get the binary in target/closh-zero.jar
.