【发布时间】:2020-03-25 12:52:29
【问题描述】:
在 clojure 文档中它说:
用法:(减少x)
以某种方式包装 x,以使 reduce 以值 x 终止
我正在尝试从具有布尔值和向量值的 reduce 函数返回。
(def bp (reduce (fn [[balanced stack] singlenum]
(def stack2 (conj stack singlenum))
(println stack2)
(if (= 2 singlenum)
(reduced [false stack2])
)
[balanced stack2]
)
[true (vector)] [1 2 3 4]
))
bp 评估为[true [1 2 3 4]],我期待[false [1 2]]。 reduce 并未终止 reduce 函数。我试图用特定值终止 reduce 函数。
【问题讨论】: