*ns* is interned in clojure.core holding the current NAMESPACE OBJECT, kept in sync by ctx-set-current-ns through a var table cached on the env (one table put on the hot path; core-bench A/B neutral). A thread binding (binding [*ns* ...]) shadows the root through var-get as usual. in-ns now returns the namespace object (Clojure); str renders a namespace as its name and pr-str as #namespace[name]. The ns-designator helper accepts namespace objects (they are tagged STRUCTS — the old table?-based check never matched them), so (ns-aliases *ns*) / (ns-unalias *ns* 'a) work — SCI and the jank syntax-quote corpus use exactly that shape. Known divergence (documented): inside an interpreted fn, *ns* reflects the fn's defining ns (jolt's resolution model rebinds current-ns per call); top-level and load-time reads match Clojure. Gate green (conformance 326x3, suite 4572 >= 4540, all batteries, specs+unit +8 *ns* rows); bench neutral.
16 lines
1 KiB
Text
16 lines
1 KiB
Text
# Specification: *ns* — the current-namespace dynamic var (stage 3).
|
|
# *ns* holds the current NAMESPACE OBJECT; (str *ns*) is its name; it tracks
|
|
# in-ns at the top level and works with the ns-introspection fns.
|
|
(use ../support/harness)
|
|
|
|
(defspec "*ns* / identity & printing"
|
|
["str of *ns*" "\"user\"" "(str *ns*)"]
|
|
["ns-name of *ns*" "(quote user)" "(ns-name *ns*)"]
|
|
["*ns* is find-ns" "true" "(= (ns-name *ns*) (ns-name (find-ns (quote user))))"]
|
|
["*ns* not a map" "false" "(map? *ns*)"]
|
|
["tracks in-ns" "\"jolt.test-ns-a\"" "(do (in-ns (quote jolt.test-ns-a)) (str *ns*))"]
|
|
["in-ns returns ns" "\"jolt.test-ns-b\"" "(str (in-ns (quote jolt.test-ns-b)))"]
|
|
["usable with ns fns" "true"
|
|
"(do (require (quote clojure.string)) (alias (quote nsv) (quote clojure.string)) (some? (get (ns-aliases *ns*) (quote nsv))))"]
|
|
["ns-unalias via *ns*" "true"
|
|
"(do (require (quote clojure.string)) (alias (quote nsw) (quote clojure.string)) (ns-unalias *ns* (quote nsw)) (nil? (get (ns-aliases *ns*) (quote nsw))))"])
|