What is the difference between an atom in Common Lisp and an atom in Clojure?

后端 未结 3 1921
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-19 07:21

The following page talks about how atoms work in Clojure. It doesn\'t say a whole lot about the differences between atoms in Clojure and other lisp dialects.

What is th

3条回答
  •  独厮守ぢ
    2021-02-19 07:54

    They are largely different and have a common conceptual basis for using the name 'Atom'

    • Atom in Common lisp refers to the idea of an indivisable thing like the origional meaning of an atom of matter.

    • Atom in clojure refers to a specific mutable data structure that changes 'atomically' that is a write to it either completes or it does not (and is subsequently retried)

    the common idea is the indivisible concept. in CL its what the thing is and in Clojure its how the thing changes.

    In Clojure Atoms are used when you need blocking mutable data that is not coordinated. for instance a single userId counter or something. Clojure also has coordinated mutable access in Refs (think bank account transfers) and atomic uncoordinated non-blocking mutable things in Agents (think log collectors for example).

提交回复
热议问题