diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-05-08 20:10:48 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-05-08 20:10:48 +0000 |
commit | 56dc8bc5e6fdfd3e358e4c0d0428ce3067485f4d (patch) | |
tree | 699c718154eea4094a97ecf2b0416c7d14d8622a /src/clj | |
parent | be302bb20730215bfa584ba0ca2c577f15b2d4c8 (diff) |
first steps in improving modularity - moving classname resolution towards consumer in: new, static calls, class literals and import. Note import is now a macro (but tolerant of quotes for backwards compatibility)
Diffstat (limited to 'src/clj')
-rw-r--r-- | src/clj/clojure/core.clj | 41 | ||||
-rw-r--r-- | src/clj/clojure/core_proxy.clj | 2 |
2 files changed, 20 insertions, 23 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 8fee8bcb..62da5a61 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1840,25 +1840,31 @@ ~@body (recur (unchecked-inc ~i))))))) -(defn import +(defn into + "Returns a new coll consisting of to-coll with all of the items of + from-coll conjoined." + [to from] + (let [ret to items (seq from)] + (if items + (recur (conj ret (first items)) (next items)) + ret))) + +(defmacro import "import-list => (package-symbol class-name-symbols*) For each name in class-name-symbols, adds a mapping from name to the class named by package.name to the current namespace. Use :import in the ns macro in preference to calling this directly." [& import-symbols-or-lists] - (let [#^clojure.lang.Namespace ns *ns*] - (doseq [spec import-symbols-or-lists] - (if (symbol? spec) - (let [n (name spec) - dot (.lastIndexOf n (. clojure.lang.RT (intCast \.))) - c (symbol (.substring n (inc dot)))] - (. ns (importClass c (. clojure.lang.RT (classForName (name spec)))))) - (let [pkg (first spec) - classes (next spec)] - (doseq [c classes] - (. ns (importClass c (. clojure.lang.RT (classForName (str pkg "." c))))))))))) - + (let [specs (map #(if (and (seq? %) (= 'quote (first %))) (second %) %) + import-symbols-or-lists)] + `(do ~@(map #(list 'clojure.core/import* %) + (reduce (fn [v spec] + (if (symbol? spec) + (conj v (name spec)) + (let [p (first spec) cs (rest spec)] + (into v (map #(str p "." %) cs))))) + [] specs))))) (defn into-array "Returns an array with components set to the values in aseq. The array's @@ -1871,15 +1877,6 @@ ([type aseq] (clojure.lang.RT/seqToTypedArray type (seq aseq)))) -(defn into - "Returns a new coll consisting of to-coll with all of the items of - from-coll conjoined." - [to from] - (let [ret to items (seq from)] - (if items - (recur (conj ret (first items)) (next items)) - ret))) - (defn #^{:private true} array [& items] (into-array items)) diff --git a/src/clj/clojure/core_proxy.clj b/src/clj/clojure/core_proxy.clj index 860621c4..93e3e0ba 100644 --- a/src/clj/clojure/core_proxy.clj +++ b/src/clj/clojure/core_proxy.clj @@ -255,7 +255,7 @@ pname (proxy-name super interfaces)] (or (RT/loadClassForName pname) (let [[cname bytecode] (generate-proxy super interfaces)] - (. (RT/getRootClassLoader) (defineClass pname bytecode)))))) + (. (deref clojure.lang.Compiler/LOADER) (defineClass pname bytecode)))))) (defn construct-proxy "Takes a proxy class and any arguments for its superclass ctor and |