6

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.

chris
  • 2,473
  • 1
  • 29
  • 28

4 Answers4

11

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

Stuart Sierra
  • 10,837
  • 2
  • 29
  • 35
5

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

user=> `(inc)
(clojure.core/inc)
user=> `(fn)
(clojure.core/fn)
Belun
  • 4,151
  • 7
  • 34
  • 51
  • Very elegant and useful at read-time. (str `inc) would be equivalent of fully-qualified-name. Any run-time solution? – chris Sep 21 '10 at 16:13
  • what do you plan on doing with the result ? – Belun Sep 21 '10 at 16:22
  • Not all functions have a fully-qualified-names (anonymous functions have not as partial....). That's a strange thing to lookup dynamically. – Nicolas Oury Sep 21 '10 at 16:34
  • @Nicolas I have modified the question to clarify that a solution for functions with fully qualified names is sufficient. – chris Sep 21 '10 at 21:13
2

type gives a fully qualified name, regardless of meta info.

Rachel K. Westmacott
  • 2,038
  • 20
  • 15
1

The output of .toString could get you started:

user=> (.toString map)
"clojure.core$map@11af7bb"
Michael Kohl
  • 66,324
  • 14
  • 138
  • 158