Skip to content

Instantly share code, notes, and snippets.

@oranenj
Created August 25, 2009 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oranenj/174831 to your computer and use it in GitHub Desktop.
Save oranenj/174831 to your computer and use it in GitHub Desktop.
(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