I may be missing some philosophical significance of the name function, but is there any reason why it can't work on Strings as well as Named-s?
user=> (name :foo) "foo" user=> (name "foo") "foo" This would clean up conditionals I have scattered about where I normalize heterogeneous collections of keywords and strings. (reduce #(let [m %1 [k v] %2] (conj m [(if (keyword? k) (name k) k) v])) {} {:foo :bar "baz" :quux}) (reduce #(let [m %1 [k v] %2] (conj m [(name k) v])) {} {:foo :bar "baz" :quux}) => {"foo" :bar, "baz" :quux} The attached patch does this with a couple of multimethods. -Drew --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj index 4f51ace..1202584 100644 --- a/src/clj/clojure/boot.clj +++ b/src/clj/clojure/boot.clj @@ -922,11 +922,6 @@ [#^clojure.lang.Reversible rev] (. rev (rseq))) -(defn name - "Returns the name String of a symbol or keyword." - [#^clojure.lang.Named x] - (. x (getName))) - (defn namespace "Returns the namespace String of a symbol or keyword, or nil if not present." [#^clojure.lang.Named x] @@ -3029,6 +3024,14 @@ [fmt & args] (print (apply format fmt args))) +(defmulti name (fn [x] (. x (getClass)))) + +(defmethod name clojure.lang.Named [x] + (. x (getName))) + +(defmethod name java.lang.String [x] + x) + (defmacro ns "Sets *ns* to the namespace named by name (unevaluated), creating it if needed. references can be zero or more of: (:refer-clojure ...)