开发者

get a clojure function's code

Is there a way in clojure to get a function's code开发者_开发知识库 after the function has been loaded?

Ie. without doing something like [untested]

(defmacro blat [x] `(do (def code ~(quote (mexpand-all x)))
                        ~x)))
(blat (defn func [abc] (...)))


You can get the source of a symbol using the clojure.repl/source function. However, this only works if the var for which the symbol resolves to is in a .clj file on the classpath. You can't, for example, do this:

user=> (defn foo [x] x)
#'user/foo
user=> (require 'clojure.repl)
nil
user=> (clojure.repl/source foo)
Source not found
nil
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜