diff --git a/sci b/sci index 4b4b8f49..d91bf4bf 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 4b4b8f49b51c5c471591fe484bdc80a58dc5f8ea +Subproject commit d91bf4bf1b831de58a4980379558aed6ce28a641 diff --git a/src/babashka/impl/socket_repl.clj b/src/babashka/impl/socket_repl.clj index 6f021c38..53cd465a 100644 --- a/src/babashka/impl/socket_repl.clj +++ b/src/babashka/impl/socket_repl.clj @@ -6,7 +6,7 @@ [clojure.java.io :as io] [clojure.string :as str] [clojure.tools.reader.reader-types :as r] - [sci.impl.interpreter :refer [opts->ctx eval-edn-vals]] + [sci.impl.interpreter :refer [opts->ctx eval-form]] [sci.impl.parser :as parser])) (set! *warn-on-reflection* true) @@ -24,7 +24,7 @@ (println)) :read (fn [_request-prompt request-exit] (if (r/peek-char in) ;; if this is nil, we reached EOF - (let [v (parser/parse-next in #{:bb})] + (let [v (parser/parse-next in #{:bb} {:current (-> sci-ctx :env deref :current-ns)})] (if (or (identical? :repl/quit v) (identical? :repl/exit v) (identical? :edamame.impl.parser/eof v)) @@ -32,18 +32,20 @@ v)) request-exit)) :eval (fn [expr] - (let [ret (eval-edn-vals (update sci-ctx - :env - (fn [env] - (swap! env assoc - '*1 *1 - '*2 *2 - '*3 *3 - '*e *e) - env)) - [expr])] + (let [ret (eval-form (update sci-ctx + :env + (fn [env] + (swap! env update-in [:namespaces 'clojure.core] + assoc + '*1 *1 + '*2 *2 + '*3 *3 + '*e *e) + env)) + expr)] ret)) - :need-prompt (fn [] true)))) + :need-prompt (fn [] true) + :prompt #(printf "%s=> " (-> sci-ctx :env deref :current-ns))))) (defn start-repl! [host+port sci-opts] (let [parts (str/split host+port #":") diff --git a/src/babashka/main.clj b/src/babashka/main.clj index a8550e71..accac39e 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -16,8 +16,6 @@ [clojure.java.shell :as shell] [clojure.string :as str] [sci.core :as sci]) - (:import [sun.misc Signal] - [sun.misc SignalHandler]) (:gen-class)) (set! *warn-on-reflection* true) @@ -259,9 +257,9 @@ Everything after that is bound to *command-line-args*.")) (let [expr (if file (read-file file) expression)] (if expr (loop [in (read-next *in*)] - (let [ctx (update ctx :bindings assoc (with-meta '*in* - (when-not stream? - {:sci/deref! true})) in)] + (let [ctx (update-in ctx [:namespaces 'user] assoc (with-meta '*in* + (when-not stream? + {:sci/deref! true})) in)] (if (identical? ::EOF in) [nil 0] ;; done streaming (let [res [(let [res (sci/eval-string expr ctx)] diff --git a/test/babashka/impl/socket_repl_test.clj b/test/babashka/impl/socket_repl_test.clj index f00a0179..7b7f41ac 100644 --- a/test/babashka/impl/socket_repl_test.clj +++ b/test/babashka/impl/socket_repl_test.clj @@ -36,13 +36,13 @@ (sh "bash" "-c" "lsof -t -i:1666")))))) (is (str/includes? (socket-command '(+ 1 2 3)) - "bb=> 6")) + "user=> 6")) (testing "ctrl-d exits normally, doesn't print nil" (is (str/ends-with? (:out (sh "bash" "-c" (if mac? ;; mac doesn't support -q "echo \"(inc 1336)\" | nc 127.0.0.1 1666" "echo \"(inc 1336)\" | nc -q 1 127.0.0.1 1666"))) - "1337\nbb=> "))) + "1337\nuser=> "))) (testing "*in*" (is (str/includes? (socket-command "*in*") "[1 2 3]")))