On Tue, Nov 11, 2008 at 2:13 PM, Drew Raines <[EMAIL PROTECTED]> wrote: > 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?
Hi, I think the philosophical point is that a String doesn't have a name, and shouldn't pretend that it does. :-) Why not just define your own utility function, e.g. (defn name-string-friendly [s] (if (instance? clojure.lang.Named s) (name s) s)) and use that wherever you've been using (name)? If (name) were to be changed, I'd vote to have it return nil for any input value other than a Named instance. Then you could write (or (name ks) ks) which is concise and very Lispy, IMHO. Graham > > 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 -~----------~----~----~----~------~----~------~--~---