views:

89

answers:

3

In Clojure, is there a more elegant way of finding the fully qualified name of a function (known to have meta info) than

(defn fully-qualified-name [fn]
  (let [fn-meta (meta fn )
        fn-ns (ns-name (:ns fn-meta))
        ]
    (str fn-ns "/" (:name fn-meta))))

A run-time solution is required. Read-time and compile-time solutions are welcome.

+1  A: 

how about syntax-quoting ? it does auto-qualification. use ` instead of '

user=> `(inc)
(clojure.core/inc)
user=> `(fn)
(clojure.core/fn)
Belun
Very elegant and useful at read-time. (str `inc) would be equivalent of fully-qualified-name. Any run-time solution?
chris
what do you plan on doing with the result ?
Belun
Not all functions have a fully-qualified-names (anonymous functions have not as partial....). That's a strange thing to lookup dynamically.
Nicolas Oury
@Belun I am building a distributed computing framework.
chris
@Nicolas I have modified the question to clarify that a solution for functions with fully qualified names is sufficient.
chris
A: 

The output of .toString could get you started:

user=> (.toString map)
"clojure.core$map@11af7bb"
Michael Kohl
also written (str map) to get the fully qualified name use (str `map)
Arthur Ulfeldt
+2  A: 

(resolve 'foo) returns the Var named "foo", with its fully-qualified name.

Stuart Sierra