如何将clojure的doc函数应用于一系列函数 [英] How can I apply clojure's doc function to a sequence of functions
问题描述
我想做一些我认为简单的事情,但事实证明不是这样,我认为解决方案可能会让我对clojure有更深入的了解,所以我想我会问这里。
I was trying to do something I thought would be simple but has turned out to be not so and I think the solution might give me a deeper understanding of clojure so I figured I'd ask here.
我想能够从clojure REPL运行以下命令:
I want to be able to run the following from a clojure REPL:
(map #(doc %) v)
其中 v
是一个向量...的东西,我不知道什么。目标是为某些功能序列打印出文档字符串,但我不知道如何表达该向量。我尝试了几件事情:(我会随机选择几个函数)
where v
is a vector of...something, I'm not sure what. The goal was to print out the doc strings for some sequence of functions, but I'm not sure how to express that vector. I've tried a couple of things: (I'll pick a few functions out at random)
[+ - first set]
['+ '- 'first 'set]
[`+ `- `first `set]
[(var +) (var -) (var first) (var set)]
[`~+ `~- `~first `~set]
。我还尝试 apply
doc
函数,但不起作用,因为 doc
是一个宏,因此不能是
apply
的参数。
None work. I also tried to apply
the doc
function but that doesn't work since doc
is a macro and as such cannot be an argument to apply
. What am I missing?
推荐答案
(doseq [f ['+ '- 'first 'set]] (eval (list 'doc f)))
这篇关于如何将clojure的doc函数应用于一系列函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!