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

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

    Atoms in Clojure and atoms in Common Lisp (and most other Lisps) are two completely unrelated concepts. They have nothing to do with each other, other than having the same name.

    There is no 'difference'. It would be asking what is the difference between a window in a house and a window on your computer screen? It does not make sense to identify differences, since the two concepts are not related.

    'Atoms' in Clojure manage state.

    'Atoms' in Lisp is a word for all data types that are not cons cells (like numbers, characters, strings, symbols, ...).

    In Lisp the function ATOM is simply defined as:

    (defun atom (object)
       (not (consp object)))
    

    Since Clojure does not have cons cells and no function consp, it is not possible to say (not (consp object)). Thus there does not exist a Lisp concept like 'atom' in Clojure. Note that Clojure has a function cons, but it does not create cons cells like in Lisp.

提交回复
热议问题