Dear Clojurians, currently the trio of require, use and import is slightly inconsistent. While use and require allow either symbols or lists, import only allows lists. (The vector notation doesn't make sense for import). So one has to specify always the full list, even if one only wants to import a single class from a package.
The patch pasted below changes this to a more uniform behaviour. One may either specify a list or a symbol in an import statement. (import 'clojure.lang.RT '(clojure.lang Var Repl)) Sincerely Meikel diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1564,14 +1564,19 @@ 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-lists] - (when import-lists - (let [#^clojure.lang.Namespace ns *ns* - pkg (ffirst import-lists) - classes (rfirst import-lists)] - (doseq [c classes] - (. ns (importClass c (. Class (forName (str pkg "." c)))))) ) - (apply import (rest import-lists)))) + [& import-symbols-or-lists] + (let [#^clojure.lang.Namespace ns *ns*] + (doseq [spec import-symbols-or-lists] + (if (seq? spec) + (let [pkg (first spec) + classes (rest spec)] + (doseq [c classes] + (. ns (importClass c (. Class (forName (str pkg "." c))))))) + (let [n (name spec) + dot (.lastIndexOf n (. clojure.lang.RT (intCast \.))) + c (symbol (.substring n (inc dot)))] + (. ns (importClass c (. Class (forName (name spec)))))))))) + (defn into-array "Returns an array with components set to the values in aseq. The array's --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---