gpt4 book ai didi

clojure - 懒惰评估问题

转载 作者:行者123 更新时间:2023-12-04 14:35:38 24 4
gpt4 key购买 nike

我有这样的代码。我可以在 repl 中运行它,但不能从命令行运行。
我想我有一个懒惰的评估问题。


; items.clj

(def items (ref []))

(defn init-items []
(map
#(dosync
(alter items conj %))
["foo" "bar" "baz" ] ))

(init-items)
(println (first @items))

$ java -jar clojure.jar items.clj
$ nil

问候。

最佳答案

知道了!

solution

Clojure 没有动力运行 map函数在 init-items因为没有返回结果。我把它包成一个 doall强制执行,并迅速。

关于clojure - 懒惰评估问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3256891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com