The keyword doc reads: "Returns a Keyword with the given namespace and name. Do not use :
in the keyword strings, it will be added automatically."
Looking at the implementation and testing in the repl, for [name] the following works:
user=> (keyword "abc")
:abc
user=> (keyword 'abc)
:abc
user=> (keyword :abc)
:abc
user=>
However, for the second signature [ns name], only the arguments as string work:
user=> (keyword "my-ns" "abc")
:my-ns/abc
user=> (keyword "my-ns" 'abc)
ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String clojure.core/keyword (core.clj:558)
user=> (keyword "my-ns" :abc)
ClassCastException clojure.lang.Keyword cannot be cast to java.lang.String clojure.core/keyword (core.clj:558)
user=> (keyword 'my-ns "abc")
ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String clojure.core/keyword (core.clj:558)
user=> (keyword *ns* "abc")
ClassCastException clojure.lang.Namespace cannot be cast to java.lang.String clojure.core/keyword (core.clj:558)
user=>
The java implementation of clojure.lang.Keyword/intern shows that only a function signature of (String, String) is supported for the call made in [ns name].
The fairly small patch at: "https://gist.github.com/1956218" for clojure.core/keyword would add some conversions-to-string in the [ns name] code to allow for different data types on par with [name], and would also allow you to specify the ns as string/symbol/namespace.
In Assembla I couldn't find any bug report related to this (?).
Would this be considered a (usability) bug or just too much perfectionism?
Regards, Frank.
PS. same issue with (symbol name) and (symbol ns name)…
PS. same issue with (symbol name) and (symbol ns name)…
See that you tried to solve it in java… while I tried to stay up in clj … but any protocol-based solution seems to be up in the air still (?).
Hopefully both interfaces can be enhanced in silmilar ways.
-FrankS.