Skip to content

Commit 3d8da63

Browse files
committed
wip
1 parent 894845c commit 3d8da63

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

src/sci/impl/namespaces.cljc

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,19 @@
436436
(sci-create-ns ctx ns-sym))
437437
(sci.impl.utils/set-namespace! (store/get-ctx) ns-sym {}))
438438

439-
(defn sci-the-ns [ctx x]
439+
(defn sci-the-ns* [ctx x]
440440
(if (instance? #?(:clj sci.lang.Namespace
441441
:cljs sci.lang/Namespace) x) x
442442
(or (sci-find-ns* ctx x)
443443
(throw (new #?(:clj Exception :cljs js/Error)
444444
(str "No namespace: " x " found"))))))
445445

446+
(defn sci-the-ns [x]
447+
(let [ctx (store/get-ctx)]
448+
(sci-the-ns* ctx x)))
449+
446450
(defn sci-ns-name* [ctx ns]
447-
(let [^sci.lang.Namespace ns (sci-the-ns ctx ns)]
451+
(let [^sci.lang.Namespace ns (sci-the-ns* ctx ns)]
448452
(types/getName ns)))
449453

450454
(defn sci-ns-name [ns]
@@ -568,7 +572,7 @@
568572
;; in this case the var will become unbound
569573
([ns var-sym]
570574
(let [ctx (store/get-ctx)
571-
ns (sci-the-ns ctx ns)
575+
ns (sci-the-ns* ctx ns)
572576
ns-name (types/getName ns)
573577
env (:env ctx)]
574578
(or (get-in @env [:namespaces ns-name var-sym])
@@ -579,7 +583,7 @@
579583
new-var))))
580584
([ns var-sym val]
581585
(let [ctx (store/get-ctx)
582-
ns (sci-the-ns ctx ns)
586+
ns (sci-the-ns* ctx ns)
583587
ns-name (types/getName ns)
584588
env (:env ctx)]
585589
(or (when-let [v (get-in @env [:namespaces ns-name var-sym])]
@@ -601,9 +605,12 @@
601605

602606
;;;; Require + resolve
603607

604-
(defn require [sci-ctx & args]
608+
(defn require* [sci-ctx & args]
605609
(apply @sci.impl.utils/eval-require-state sci-ctx args))
606610

611+
(defn require [& args]
612+
(apply require* (store/get-ctx) args))
613+
607614
(defn use [sci-ctx & args]
608615
(apply @sci.impl.utils/eval-use-state sci-ctx args))
609616

@@ -626,23 +633,24 @@
626633
(defn sci-ns-resolve
627634
([ns sym]
628635
(let [ctx (store/get-ctx)]
629-
(sci.impl.vars/with-bindings {sci.impl.utils/current-ns (sci-the-ns ctx ns)}
636+
(sci.impl.vars/with-bindings {sci.impl.utils/current-ns (sci-the-ns* ctx ns)}
630637
(sci-resolve* ctx sym))))
631638
([ns env sym]
632639
(let [ctx (store/get-ctx)]
633-
(sci.impl.vars/with-bindings {sci.impl.utils/current-ns (sci-the-ns ctx ns)}
640+
(sci.impl.vars/with-bindings {sci.impl.utils/current-ns (sci-the-ns* ctx ns)}
634641
(sci-resolve* ctx env sym)))))
635642

636643
(defn sci-requiring-resolve
637-
([sci-ctx sym]
638-
(if (qualified-symbol? sym)
639-
(or (sci-resolve* sci-ctx sym)
640-
(let [namespace (-> sym namespace symbol)]
641-
(require sci-ctx namespace)
642-
(sci-resolve* sci-ctx sym)))
643-
(throw (new #?(:clj IllegalArgumentException
644-
:cljs js/Error)
645-
(str "Not a qualified symbol: " sym))))))
644+
[sym]
645+
(let [sci-ctx (store/get-ctx)]
646+
(if (qualified-symbol? sym)
647+
(or (sci-resolve* sci-ctx sym)
648+
(let [namespace (-> sym namespace symbol)]
649+
(require* sci-ctx namespace)
650+
(sci-resolve* sci-ctx sym)))
651+
(throw (new #?(:clj IllegalArgumentException
652+
:cljs js/Error)
653+
(str "Not a qualified symbol: " sym))))))
646654

647655
(defn sci-find-var [sym]
648656
(if (qualified-symbol? sym)
@@ -1560,7 +1568,7 @@
15601568
'rem (copy-core-var rem)
15611569
'remove (copy-core-var remove)
15621570
'remove-ns (copy-var sci-remove-ns clojure-core-ns {:name 'remove-ns})
1563-
'require (copy-var require clojure-core-ns {:ctx true :copy-meta-from 'clojure.core/require})
1571+
'require (copy-var require clojure-core-ns {:copy-meta-from 'clojure.core/require})
15641572
'reset-meta! (copy-core-var reset-meta!)
15651573
'rest (copy-core-var rest)
15661574
'repeatedly (copy-core-var repeatedly)
@@ -1584,7 +1592,7 @@
15841592
'rseq (copy-core-var rseq)
15851593
'random-sample (copy-core-var random-sample)
15861594
'repeat (copy-core-var repeat)
1587-
'requiring-resolve (copy-var sci-requiring-resolve clojure-core-ns {:ctx true :name 'requiring-resolve})
1595+
'requiring-resolve (copy-var sci-requiring-resolve clojure-core-ns {:name 'requiring-resolve})
15881596
'run! (copy-core-var run!)
15891597
'set? (copy-core-var set?)
15901598
'sequential? (copy-core-var sequential?)
@@ -1639,7 +1647,7 @@
16391647
'take-last (copy-core-var take-last)
16401648
'take-nth (copy-core-var take-nth)
16411649
'take-while (copy-core-var take-while)
1642-
'the-ns (copy-var sci-the-ns clojure-core-ns {:name 'the-ns :ctx true})
1650+
'the-ns (copy-var sci-the-ns clojure-core-ns {:name 'the-ns})
16431651
'trampoline (copy-core-var trampoline)
16441652
'transduce (copy-core-var transduce)
16451653
'transient (copy-core-var transient)
@@ -1745,7 +1753,7 @@
17451753
(defn dir-fn
17461754
[ctx ns]
17471755
(let [current-ns (sci.impl.utils/current-ns-name)
1748-
the-ns (sci-the-ns ctx
1756+
the-ns (sci-the-ns* ctx
17491757
(get (sci-ns-aliases* ctx current-ns) ns ns))]
17501758
(sort (map first (sci-ns-publics* ctx the-ns)))))
17511759

0 commit comments

Comments
 (0)