File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 1065
1065
;; Namespace Utilities ;;
1066
1066
;;;;;;;;;;;;;;;;;;;;;;;;;
1067
1067
1068
- (defn ^:private get-namespace
1069
- "Get the Namespace named by ns-sym."
1068
+ (defn the-ns
1069
+ "If v is a symbol, return the Namespace named by that symbol if it
1070
+ exists. If v is a Namespace, return it. Otherwise, throw an exception."
1071
+ [v]
1072
+ (cond
1073
+ (symbol? v)
1074
+ (.get basilisp.lang.runtime/Namespace v)
1075
+
1076
+ (instance? basilisp.lang.runtime/Namespace v)
1077
+ v
1078
+
1079
+ :else
1080
+ (throw
1081
+ (ex-info "Expected a Symbol or a Namespace"
1082
+ {:value v
1083
+ :type (builtins/type v)}))))
1084
+
1085
+ (defn create-ns
1086
+ "Create a Namespace with the name ns-sym or return the existing one
1087
+ if it already exists."
1070
1088
[ns-sym]
1071
1089
(.get-or-create basilisp.lang.runtime/Namespace ns-sym))
1072
1090
1152
1170
- :rename {sym1 new-sym1}, to rename all the specified symbols to the given new name"
1153
1171
[ns-sym & filters]
1154
1172
(let [current-ns *ns*
1155
- ns (get-namespace ns-sym)
1173
+ ns (the-ns ns-sym)
1156
1174
filter-map (apply hash-map filters)]
1157
1175
(if-not (seq filters)
1158
1176
(.refer-all current-ns ns)
1205
1223
(let [ns-sym (first v)
1206
1224
opts (apply hash-map (rest v))]
1207
1225
(importlib/import-module (name ns-sym))
1208
- (let [new-ns (get-namespace ns-sym)]
1226
+ (let [new-ns (the-ns ns-sym)]
1209
1227
;; Add the namespace alias
1210
1228
(.add-alias current-ns (or (:as opts) ns-sym) new-ns)
1211
1229
You can’t perform that action at this time.
0 commit comments