diff --git a/sci b/sci index 4fa88132..dcfea77c 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 4fa8813270910d71a5fd7d590962fa1babbc19db +Subproject commit dcfea77c3172c78a6cb053ff51a6faae154b34dc diff --git a/src/babashka/impl/socket_repl.clj b/src/babashka/impl/socket_repl.clj index df3b3fb2..59b1bf5c 100644 --- a/src/babashka/impl/socket_repl.clj +++ b/src/babashka/impl/socket_repl.clj @@ -6,14 +6,14 @@ [clojure.java.io :as io] [clojure.string :as str] [clojure.tools.reader.reader-types :as r] - [sci.core :refer [eval-string]] + [sci.impl.interpreter :refer [opts->ctx eval-edn-vals]] [sci.impl.parser :as parser])) (set! *warn-on-reflection* true) (defn repl "REPL with predefined hooks for attachable socket server." - [sci-opts] + [sci-ctx] (let [in (r/indexing-push-back-reader (r/push-back-reader *in*))] (m/repl :init #(do (println "Babashka" @@ -32,13 +32,13 @@ v)) request-exit)) :eval (fn [expr] - (let [ret (eval-string (pr-str expr) - (update sci-opts - :bindings - merge {'*1 *1 - '*2 *2 - '*3 *3 - '*e *e}))] + (let [ret (eval-edn-vals (update-in sci-ctx + [:namespaces 'clojure.core] + merge {'*1 *1 + '*2 *2 + '*3 *3 + '*e *e}) + [expr])] ret)) :need-prompt (fn [] true)))) @@ -49,12 +49,13 @@ [(first parts) (Integer. ^String (second parts))]) host+port (if-not host (str "localhost:" port) host+port) + sci-ctx (opts->ctx sci-opts) socket (server/start-server {:address host :port port :name "bb" :accept babashka.impl.socket-repl/repl - :args [sci-opts]})] + :args [sci-ctx]})] (println "Babashka socket REPL started at" host+port) socket)) diff --git a/test/babashka/impl/socket_repl_test.clj b/test/babashka/impl/socket_repl_test.clj index d41f99c1..9e440094 100644 --- a/test/babashka/impl/socket_repl_test.clj +++ b/test/babashka/impl/socket_repl_test.clj @@ -48,6 +48,11 @@ (testing "*command-line-args*" (is (str/includes? (socket-command '*command-line-args*) "\"a\" \"b\" \"c\""))) + (testing "&env" + (socket-command '(defmacro bindings [] (mapv #(list 'quote %) (keys &env)))) + (socket-command '(defn bar [x y z] (bindings))) + (is (str/includes? (socket-command '(bar 1 2 3)) + "[x y z]"))) (finally (if tu/jvm? (stop-repl!)