Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure rand nth在编译后总是产生相同的结果_Clojure - Fatal编程技术网

Clojure rand nth在编译后总是产生相同的结果

Clojure rand nth在编译后总是产生相同的结果,clojure,Clojure,我已经使用core.clj通过Leiningen创建了一个项目: (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

我已经使用core.clj通过Leiningen创建了一个项目:

(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 n?

问题不在于rand n,而是因为let语句中的结果符号是在编译阶段生成的@贝亚莫在这里给出了答案: