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

后端 未结 3 1916
爱一瞬间的悲伤
爱一瞬间的悲伤 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:38

    In all Lisps atoms are symbolic expressions that are not lists (except empty lists). They are also called atomic S-expressions. What's atomic (indivisible) in it? Historically the lists were something that could be divided into smaller parts where atoms (but not non-empty lists) contained within them couldn't.

    In Clojure there are also atomic S-expressions but there is also a data structure called Atom which allows one to create mutable data objects that can be accessed by multiple threads. What's atomic in them? The operation.

    If you modify an Atom its state will be successfuly changed or not. There won't be a situation that a half of it (e.g. some vector) will change and a half will not. If the operation is unsuccessful then it is retried and a current thread waits until it completes.

    What is the difference between Lisp's atoms and Clojure's Atoms? The abstraction level. Lisp's atoms are a class of symbolic expressions, whereas Clojure's Atoms are a class of data structures used to handle shared data.

提交回复
热议问题