diff --git a/src/sci/impl/analyzer.cljc b/src/sci/impl/analyzer.cljc index 9a8d8023..825bf72d 100644 --- a/src/sci/impl/analyzer.cljc +++ b/src/sci/impl/analyzer.cljc @@ -1355,14 +1355,6 @@ (let [snd (second expr)] (->constant snd))) -(defn analyze-in-ns [ctx expr] - (let [ns-expr (analyze ctx (second expr))] - (sci.impl.types/->Node - (let [ns-sym (types/eval ns-expr ctx bindings)] - (set-namespace! ctx ns-sym nil) - nil) - nil))) - (defn analyze-import [_ctx expr] (let [args (rest expr) stack (assoc (meta expr) @@ -1466,8 +1458,7 @@ import (analyze-import ctx expr) or (return-or ctx expr (rest expr)) and (return-and ctx expr (rest expr)) - recur (return-recur ctx expr (analyze-children (without-recur-target ctx) (rest expr))) - in-ns (analyze-in-ns ctx expr)) + recur (return-recur ctx expr (analyze-children (without-recur-target ctx) (rest expr)))) :else (try (if (macro? f) diff --git a/src/sci/impl/namespaces.cljc b/src/sci/impl/namespaces.cljc index c92fda57..333af72b 100644 --- a/src/sci/impl/namespaces.cljc +++ b/src/sci/impl/namespaces.cljc @@ -507,6 +507,12 @@ (assert (symbol? ns-sym)) (sci.impl.utils/namespace-object (:env ctx) ns-sym false nil)) +(defn sci-in-ns [ctx ns-sym] + (assert (symbol? ns-sym)) + (when-not (sci-find-ns ctx ns-sym) + (sci-create-ns ctx ns-sym)) + (sci.impl.utils/set-namespace! ctx ns-sym {})) + (defn sci-the-ns [ctx x] (if (instance? #?(:clj sci.lang.Namespace :cljs sci.lang/Namespace) x) x @@ -1225,6 +1231,7 @@ 'ex-cause (copy-core-var ex-cause) 'find-ns (core-var 'find-ns sci-find-ns true #_{:sci.impl/op needs-ctx}) 'create-ns (core-var 'create-ns sci-create-ns true #_{:sci.impl/op needs-ctx}) + 'in-ns (core-var 'in-ns sci-in-ns true #_{:sci.impl/op needs-ctx}) 'find-var (core-var 'find-var sci-find-var true) 'first (copy-core-var first) 'float? (copy-core-var float?) diff --git a/test/sci/namespaces_test.cljc b/test/sci/namespaces_test.cljc index 7b776e3c..beafdb7b 100644 --- a/test/sci/namespaces_test.cljc +++ b/test/sci/namespaces_test.cljc @@ -107,6 +107,11 @@ (is (= :clojure.string/foo (eval* "(in-ns 'foo) (require '[clojure.string :as str]) ::str/foo"))) (is (= :clojure.string/foo (eval* "(ns foo (:require [clojure.string :as s])) ::s/foo")))) +(deftest in-ns-test + (is (= :user/foo (eval* "::foo"))) + (is (= :bar/foo (eval* "(in-ns 'bar) ::foo"))) + (is (= :bar/foo (eval* "(in-ns 'bar) (def just-one-ns ::foo) (in-ns 'bar) just-one-ns")))) + (deftest vars-partitioned-by-namespace-test (is (= 10 (eval* "(in-ns 'foo) (def x 10) (in-ns 'bar) (def x 11) (in-ns 'foo) x"))))