我希望了解下面的代码如何工作,它是为以下问题而设计的:“给定一个整数序列,找到一个连续的子序列,使其元素的和最大”
defn max-subseq-sum [coll]
(->> (take-while seq (iterate rest coll)) ; tails (1)
(mapcat #(reductions conj [] %)) ; inits (2)
(apply max-key #(reduce + %)))) ; max sum
我希望能看到表格(1)、(2)等的输出结果。虽然我可以在Cursive中设置断点,但我不知道如何获取这些值。我已经尝试定义本地变量,例如
(defn max-subseq-sum [coll]
(->> (take-while seq (iterate rest coll)) ; tails
(let [d #(reductions conj [] %)]
d ) ; inits
(apply max-key #(reduce + %)))
)
(max-subseq-sum [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1])
但我仍然不明白如何查看d,例如
如何解决这个问题?