开发者

Clojure: fully qualified name of a function

开发者 https://www.devze.com 2023-01-17 12:34 出处:网络
In Clojure, is there a more elegant way of finding the fully qualified name of a function (known to have meta info) than

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

(def开发者_StackOverflown 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.


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


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

user=> `(inc)
(clojure.core/inc)
user=> `(fn)
(clojure.core/fn)


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


The output of .toString could get you started:

user=> (.toString map)
"clojure.core$map@11af7bb"
0

精彩评论

暂无评论...
验证码 换一张
取 消