Well, if anyone want to check, I'm working on a "REPL Detection" feature, currently on the branch detect-repl-type
.
It currently detects (and connects to) Babashka, ClojureScript (Lumo, or clj
pointing to a browser/node socket REPL) and ClojureCLR. There's still lots of room for improvements (for example, doc for var
isn't working yet) but it's a start 🙂
Also, Joker's socket REPL is kinda supported, but there's a problem with connections so it's not there yet.
i've just tried with babashka. initially after "Chlorine: Connect Socket REPL" i got:
bb=> :using-unknown-repl
bb=> :using-unknown-repl
bb=> bb=>
but after that evaluation seemed to work fine. is this expected?Yes, it is expected for now. It was happening because of this issue: https://github.com/borkdude/babashka/issues/85
But its already fixed on the new version.
try upgrading to v0.0.23
Yes, upgrading works, the code for Chlorine was written before the fix 🙂
thanks 🙂
i just tried clojure clr. below i'm using a hypothetical ns named alens.core (though note that it hasn't been created / loaded right after starting the clojure clr process). i get an error for evaluation. chlorine sends:
(in-ns 'alens.core)(try (clojure.core/let [res (+ 1 1) res (clojure.core/cond #?(:cljs false :default (clojure.core/ratio? res)) (clojure.core/symbol (clojure.core/str "#repl-tooling/literal-render \"" (clojure.core/pr-str res) "\"")) (clojure.core/symbol? res) (clojure.core/symbol (clojure.core/str "#unrepl/bad-symbol [nil " (clojure.core/pr-str (clojure.core/str res)) "]")) (clojure.core/keyword? res) (clojure.core/symbol (clojure.core/str "#unrepl/bad-keyword [" (clojure.core/pr-str (namespace res)) " " (clojure.core/pr-str (clojure.core/name res)) "]")) (clojure.core/->> res type str (clojure.core/re-find #"Big(Decimal|Float)")) (clojure.core/symbol (clojure.core/str "#unrepl/bigdec "res)) (clojure.core/->> res type str (clojure.core/re-find #"BigInt")) (clojure.core/symbol (clojure.core/str "#unrepl/bigint "res)) :else res)] ['tooling$eval-res 'G__2 {:result (clojure.core/pr-str res)}]) (catch System.Exception e ['tooling$eval-res 'G__2 {:error (clojure.core/pr-str e)}]))
i get:
#object[Namespace 0x4684feed "alens.core"]
Syntax error (InvalidOperationException) compiling at (REPL:1:31).
Unable to resolve symbol: + in this context
alens.core=>
if an appropriate ns form (e.g. (ns alens.core)) is evaluated before the let form, it works. presumably this is because using ns leads to clojure.core being made available in the corresponding ns.Yes, this is somehow expected. I'm using in-ns
to enter the namespace, and if the ns doesn't exist it doesn't include any clojure.core
functions
so i tried load file first, but i get:
#object[Namespace 0x581e8372 "user"]
Syntax error (InvalidOperationException) compiling at (REPL:4:230).
Unable to find static field: getProperty in
user=>
not sure why yetI think in CLJ, unrepl
creates the namespace for us
ah -- i looked into porting unrepl to clr clojure a bit back, but it looked like it would be quite a bit of work 🙂
load-file
is completely JVM dependent 😞
i wonder if there is harm in sending (ns my-ns) before the (in-ns 'my-ns)
a lot of clr clojure is similar to jvm clojure fwiw -- may not be hard to port that part
i guess if one is doing something to exclude various clojure bits, doing (ns my-ns) may not be a good idea
Yes, but now we're expanding quite a bit (Babashka, Joker, ClojureCLR, Lumo, Plank to start), so probably we'll need to restrict some commands
it is a tricky business
Yes, it is 😄. To be honest, I'm surprised it is even working!
i didn't want to adversely affect the existing functionality -- so when i tried to get clr stuff working before i tried to provide separate lower level networking pieces
Like, I've got ClojureCLR autocomplete on one file and it was completely incidental
neat!
regarding load-file, i had something like this before:
(defn load-file! []
(let [editor (atom/current-editor)
file-name (.getPath editor)
;; canonicalize path separator for Java -- this avoids problems
;; with \ causing 'bad escape characters' in the strings below
file-name (str/replace file-name "\\" "/")
code (if (or (need-cljs? editor)
(need-cljr? editor))
(str "(do "
" (println \"Loading \" \"" file-name "\")"
" (load-file \"" file-name "\"))")
(str "(do"
" (require 'clojure.string)"
" (println \"Loading\" \"" file-name "\")"
" (try "
" (let [path \"" file-name "\""
;; if target REPL is running on *nix-like O/S...
" nix? (clojure.string/starts-with? (System/getProperty \"user.dir\") \"/\")"
;; ...and the file path looks like Windows...
" win? (clojure.string/starts-with? (subs path 1) \":/\")"
;; ...extract the driver letter...
" drv (clojure.string/lower-case (subs path 0 1))"
;; ...and map to a Windows Subsystem for Linux mount path:
" path (if (and nix? win?) (str \"/mnt/\" drv (subs path 2)) path)]"
" (load-file path))"
" (catch Throwable t"
" (doseq [e (:via (Throwable->map t))]"
" (println (:message e))))))"))]
(evaluate-aux editor
(ns-for editor)
(.getFileName editor)
1
0
code
#(atom/info "Loaded file" file-name))))
and there was an appropriate need-cljr?
There's none yet, but I'm currently adding it
sounds great 🙂