获取clojure函数的代码 [英] get a clojure function's code
本文介绍了获取clojure函数的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在clojure中有一种方法在函数加载后获取函数的代码?
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] (...)))
推荐答案
您可以使用 clojure.repl / source
函数。但是,这只有在符号解析到的var位于类路径上的.clj文件中时才有效。例如,您无法执行此操作:
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
这篇关于获取clojure函数的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文