Created
August 25, 2009 17:12
-
-
Save oranenj/174831 to your computer and use it in GitHub Desktop.
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
(defn namespace-for [sym] | |
(let [ns-sym (symbol sym)] | |
(or (.lookupAlias *ns* ns-sym) | |
(clojure.lang.Namespace/find ns-sym)))) | |
(defn var->symbol [#^clojure.lang.Var v] | |
(symbol (str (.ns v)) (str (.sym v)))) | |
(defn resolve-symbol [sym] | |
(let [ns (when (.getNamespace sym) | |
(namespace-for (.getNamespace sym))) | |
name (str (name sym)) | |
res (resolve sym)] | |
(cond | |
(and res (class? res)) (symbol (.getCanonicalName res)) | |
(and res (var? res)) (var->symbol res) | |
(not ns) (symbol (str *ns*) name) | |
:else (symbol (str ns) name)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment