我在 refs 中有两张地图,并希望在一次交易中将它们相互关联。
我的功能如下所示:
(defn assoc-two
[one two]
(let [newone (assoc @one :two two)
newtwo (assoc @two :one one)]
(ref-set one newone)
(ref-set two newtwo)))
现在我这样打电话assoc-two
:
(dosync (assoc-two (ref {}) (ref {})))
在这一点上,我得到了 StackOverflowError 。
我也试过这个:
(defn alter-two
[one two]
(alter one assoc :two two)
(alter two assoc :one one))
是否有办法以one
具有条目引用的方式执行此操作,two
反之亦然并且仍在一个事务中?