我有一个包含参考列表的原子。我将如何更新原子内的参考列表?我尝试了以下但它不起作用。
(def theatom (atom []))
(def mylist [1 2 3 4])
(reset! theatom (map ref mylist))
(swap! theatom (fn [anAtom]
(map (fn [theRef] (dosync (alter theRef inc))) theatom)
))
(println (map deref @theatom))
这个想法是将每个参考值增加一。然后我应该打印 [2 3 4 5]。