Created
March 2, 2012 06:28
-
-
Save KSCGroup/1956218 to your computer and use it in GitHub Desktop.
patch to clojure.core/keyword to allow different types for [ns name] interface, on par with [name]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in-ns 'clojure.core) | |
(defn keyword-fs | |
"Returns a Keyword with the given namespace and name. Do not use : | |
in the keyword strings, it will be added automatically." | |
{:tag clojure.lang.Keyword | |
:added "1.0" | |
:static true} | |
([name] (cond (keyword? name) name | |
(symbol? name) (clojure.lang.Keyword/intern ^clojure.lang.Symbol name) | |
(string? name) (clojure.lang.Keyword/intern ^String name))) | |
([ns name] | |
(let [ns-str (cond (instance? clojure.lang.Namespace ns) (str ns) | |
(symbol? ns) (str ns) | |
(keyword? ns) (str (when-let [n (namespace ns)] (str n "/")) | |
(clojure.core/name ns)) | |
true ns) | |
name-str (cond (symbol? name) (str name) | |
(keyword? name) (str (when-let [n (namespace name)] (str n "/")) | |
(clojure.core/name name)) | |
true name)] | |
(clojure.lang.Keyword/intern ^String ns-str ^String name-str)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment