在加载函数后,有没有办法在clojure中获取函数的代码?
IE浏览器.没做像[未经测试]的事情
(defmacro blat [x] `(do (def code ~(quote (mexpand-all x)))
~x)))
(blat (defn func [abc] (...)))
Run Code Online (Sandbox Code Playgroud)
您可以使用该clojure.repl/source函数获取符号的来源.但是,这仅在符号解析为的var位于类路径上的.clj文件中时才有效.例如,你不能这样做:
user=> (defn foo [x] x)
#'user/foo
user=> (require 'clojure.repl)
nil
user=> (clojure.repl/source foo)
Source not found
nil
Run Code Online (Sandbox Code Playgroud)