As far I know, atoms are any of - numbers, booleans and strings in Scheme. But when I run the atom?
function on empty list - (atom? '())
- it returns true #t
value.
What am I missing here? Does it have to with my Scheme language implementation i.e. Chicken Scheme?
atom
comes from McCarthy's original 1960 lisp paper. It was a lisp with two types, symbols and pairs. The empty list is just a synonym for the symbol nil
and it was self evaluating. (atom ())
is the same as (atom nil)
and both are true while (atom (cons x y))
evaluates to the false value nil
. Common Lisp is a direct descendant with more than two types, however it still works the same for code that only cares about pairs and symbols. As a design decsetion anything that is not pairs are atoms and thus:
(defun (atom x)
(not (consp x)))
Scheme standards, as in the RNRS and R7RS being the latest, does not have atom?
as a primitive. When that said it might be that some scheme implementation has it. While it would be least surprising to be implemented in the same way as Common Lisp, namely:
(define (atom? x)
(not (pair? x)))
Paul Graham wrote an excellent article called The roots of Lisp which I highly recommend.