我已经通过 Leiningen 使用 core.clj 创建了项目:
(ns cotd.core
(:gen-class)
(:use [clojure.repl :only (doc)]))
(defmacro eval-doc
[form]
(let [resulting-symbol (eval form)]
`(doc ~resulting-symbol)))
(defn- random-function-name []
(rand-nth (keys (ns-publics 'clojure.core))))
(defn -main
"Display random doc page"
[& args]
(eval-doc (random-function-name)))
在编译和运行之后,它总是产生相同的结果:
$ java -jar cotd.jar
-------------------------
clojure.core/unchecked-negate
([x])
Returns the negation of x, a long.
Note - uses a primitive operator subject to overflow.
$ java -jar cotd.jar
-------------------------
clojure.core/unchecked-negate
([x])
Returns the negation of x, a long.
Note - uses a primitive operator subject to overflow.
但是连续两次调用:
(do
(eval-doc (random-function-name))
(eval-doc (random-function-name))))
它在单个“调用”中产生两个不同的结果。
我尝试过的是谷歌搜索、阅读等,但我不知道发生了什么……
如何动态调用这个 rand-nth?