diff --git a/src/sci/impl/namespaces.cljc b/src/sci/impl/namespaces.cljc index a37672ad..9238937a 100644 --- a/src/sci/impl/namespaces.cljc +++ b/src/sci/impl/namespaces.cljc @@ -334,7 +334,7 @@ (defn has-root-impl [sci-var] (vars/hasRoot sci-var)) -;;;; Namespaces +;;;; Namespaces / vars (defn sci-ns-name [^sci.impl.vars.SciNamespace ns] (vars/getName ns)) @@ -451,6 +451,13 @@ (swap! env assoc-in [:namespaces ns-name var-sym] new-var) new-var))))) +(defn sci-bound? + [sci-var] + ;; see https://github.com/clojure/clojure/blob/cbb3fdf787a00d3c1443794b97ed7fe4bef8e888/src/jvm/clojure/lang/Var.java#L190 + (or (vars/hasRoot sci-var) + (some? (vars/get-thread-binding sci-var)) + false)) + ;;;; End namespaces ;;;; Eval and read-string @@ -1072,7 +1079,7 @@ '-' (copy-core-var -') '*' (copy-core-var *') 'boolean-array (copy-core-var boolean-array) - 'bound? (copy-core-var bound?) + 'bound? (copy-core-var sci-bound?) 'byte-array (copy-core-var byte-array) 'bigint (copy-core-var bigint) 'bytes? (copy-core-var bytes?) diff --git a/test/sci/core_test.cljc b/test/sci/core_test.cljc index 9f0358bc..086f0ff9 100644 --- a/test/sci/core_test.cljc +++ b/test/sci/core_test.cljc @@ -1072,6 +1072,13 @@ (is (= '(/ 100 (inc 9)) (eval* "(macroexpand '(->> 9 inc (/ 100)))"))))) +(deftest bound-test + (is (false? (eval* "(def x) (bound? #'x)"))) + (is (true? (eval* "(def x 1) (bound? #'x)"))) + (is (false? (eval* "(def ^:dynamic x) (bound? #'x)"))) + (is (true? (eval* "(def ^:dynamic x) (binding [x 1] (bound? #'x))"))) + (is (false? (eval* "(def ^:dynamic x) (binding [x 1]) (bound? #'x)")))) + ;;;; Scratch (comment