clojure reduced函数的目的是什么(在clojure 1.5中添加,https: //clojure.github.io/clojure/clojure.core-api.html#clojure.core/reduced )
我找不到任何例子.医生说:
以某种方式包装x,使得reduce将以值x终止.
还有一个reduced?熟悉它
如果x是对reduce的调用的结果,则返回true
当我尝试一下时,例如(reduce + (reduced 100)),我得到一个错误而不是100.当我事先知道结果时,为什么我会减少一些东西呢?由于它被添加可能有一个原因,但谷歌搜索clojure reduced仅包含reduce结果.
我想要突破下面的循环,并在第10行评估为真时返回最佳最小值.我用print语句查看了输出,当第10行评估为true时,它找到了我正在寻找但仍在重复的数据.在Clojure中有一种方法可以在语句求值为true时停止循环吗?或者我应该使用除循环之外的其他东西?
(defn minimax [board max-mark min-mark depth best-score]
(loop [board board
max-mark max-mark
min-mark min-mark
depth depth
best-score best-score]
(if (= best-score (best-min-score board max-mark min-mark depth))
(best-max-move board max-mark min-mark depth)
(do
(if (= best-score (best-min-score board min-mark max-mark depth))
(best-min-move board min-mark max-mark depth)
(recur
(b/make-move-on board (remaining-scores board max-mark min-mark depth) max-mark)
min-mark
max-mark
(inc depth)
(dec best-score)))))))
Run Code Online (Sandbox Code Playgroud)