Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Clojure 代码中到处使用 refs,然后我意识到我ref-set到处都在使用。这会破坏 STM 的变化历史吗?还是我应该alter只使用并ref-set初始化参考?
ref-set
alter
我不确定差异是否仅仅是语法上的,alter最终还是会调用ref-set。有人可以启发我吗?
(alter aref f arg1 ... argn)
基本上是一样的
(ref-set aref (f @aref arg1 ... argn))
与reset!和的原子类似swap!。
reset!
swap!