On Thu, Dec 1, 2011 at 10:00 AM, joegallo <joega...@gmail.com> wrote: > Here are some things I've run across in Clojure that seem asymmetric to me > -- I looked through Jira for issues related to these, but I didn't find any > (of course, I might have just missed them). Some of these might be valid > enhancements that would make sense to add, some of them might be a case of > me having a bad mental model and wanting the wrong thing from the language. > I'm hoping to get some feedback to help me determine which is which, and > then I'll write some patches for the ideas that are good ones. I've tried > to avoid making any statements about the world (e.g. x is y), these are all > just statements about my personal experience (e.g. x seems like y to me). > > 1. > user=> (keyword 'foo) > :foo > user=> (keyword "foo") > :foo > user=> (keyword :foo) > :foo > user=> (symbol "foo") > foo > user=> (symbol 'foo) > foo > user=> (symbol :foo) > ClassCastException clojure.lang.Keyword cannot be cast to java.lang.String > clojure.core/symbol (core.clj:522) > > I've never wanted to create a symbol from a keyword, but this seems > asymmetrical to me. > > 2. > user=> (name 'user) > "user" > user=> (name :user) > "user" > user=> (name "user") > "user" > user=> (name *ns*) > ClassCastException clojure.lang.Namespace cannot be cast to > clojure.lang.Named clojure.core/name > (core.clj:1488) > > I think of namespaces as being a thing that has a name, so I would expect to > be able to call name on them. I always do this first, and then it blows up, > and then I remember ns-name, but that returns a symbol, not a string (which > I also always forget), so then I finally have to pipe that through name or > str, which ends up seeming messier than it should to me. > > user=> (name (ns-name *ns*)) > "user" > > One solution to that would be name namespaces a clojure.lang.Named, where > they return their own name -- which seems reasonable to me. But that would > lead us to this next case, below. > > 3. > user=> (namespace 'foo) > nil > user=> (namespace 'user/foo) > "user" > user=> (namespace :foo) > nil > user=> (namespace ::foo) > "user" > user=> (namespace *ns*) > ClassCastException clojure.lang.Namespace cannot be cast to > clojure.lang.Named clojure.core/namespace (core.clj:1496) > > If we make Namespaces a clojure.lang.Named, then they'll also need to have > an implementation of getNamespace. I suppose we could return the > namespace's name, but does that imply that a namespace is in itself? That > seems wrong to me. Another option would be to return nil, which indicates > that a namespace is not in a namespace, which is true, but possibly > confusing. A third possibility would be to split Named into Named (has a > name) and Namespaced (has a namespace), and then we don't have this issue at > all -- we'd be free to say that namespaces are Named, but not > Namespaced. > > 4. > user=> (symbol "bar") > bar > user=> (symbol 'bar) > bar > user=> (symbol "foo" "bar") > foo/bar > user=> (symbol "foo" 'bar) > ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String > clojure.core/symbol > (core.clj:523) > user=> (symbol 'foo 'bar) > ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String > clojure.core/symbol > (core.clj:523) > user=> (symbol *ns* > 'bar) > ClassCastException clojure.lang.Namespace cannot be cast to > java.lang.String clojure.core/symbol > (core.clj:523) > user=> (symbol *ns* "bar") > ClassCastException clojure.lang.Namespace cannot be cast to > java.lang.String clojure.core/symbol > (core.clj:523)
#4 is the biggest pain point for me, having symbol take a Namespace and a Symbol would get rid of a lot of calls that look like (symbol (name (ns-name *ns*)) (name sym)) and replace them with (symbol *ns* sym) > > I always forget that symbol allows a string or a symbol for first argument, > but that when you have two arguments, they must both be strings. It's > another "d'oh!" thing for me that I find myself correcting a lot. I'd also > like to be able to construct a symbol with a namespace object directly, not > just the string that represents the namespace's name. > > Anyway, what do you think? If there are any smart ideas here, I'd be happy > to create a jira ticket and attach a patch with tests. > > Joe > > -- > 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 > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en