What is called an atom in Clojure is something completely different than what is called an atom in other Lisps. In classic Lisp, an atom represents a single value, defined as non-zero or non-cons cell (pair):
(define (atom? x) (not (or (pair? x) (null? x ))))
In Clojure, an atom is a reference type of concurrency. Atoms in Clojure can be either single-valued or collections / sequences where updating (a changed state change) is guaranteed to happen atomically.
Clojure has many more reference types than a match list in Lisp, and there are all types of Java gateway collections to be reckoned with. This makes it difficult to define a single value check.
If you want it, the easiest check is to see if you can count something. Considering (source counted) , it refers to clojure.lang.RT / count and countFrom. There are several classes / interfaces that I included in the following function:
=> (defn single-valued? [x] (not (or (nil? x) (.. x getClass isArray) (some
Since (seq []) evaluates to nil , it is not considered unambiguous. Of course, java objects with multiple fields, as well as Clojure deftypes / defrecords, will be registered as such, even if they are composite objects.
source share