1

In The Little Schemer (4th Ed.) it is claimed that a list for which null? is false contains at least one atom, or so I understand from my reading of the text.

This doesn't make sense to me, since (atom '()) is false, and we can stick those into a list to make it non-null:

> (null? '(()))
#f

So my question is, is this a mistake in my reading, or a matter of definitions? Since it's not in the errata I assume such a well-studied book wouldn't have a mistake like this.

If we considered (()) to be the same as (() . ()) or even (cons '() '()) and then considered cons an atom then I could see how you can get there, but I don't think that's what's going on.

(this was tested in Racket 7.0, with the definition of atom? given in the book, i.e.

(define atom?
  (lambda (x)
  (and (not (pair? x)) (not (null? x)))))

I know this doesn't cover funny Racket features, but should be sufficient here.)

Alexis King
  • 43,109
  • 15
  • 131
  • 205
  • As far as I know, at least from Common Lisp, `nil` (a. k. a. `()`) is an atom, but I have also found the definition you gave a lot online. The former creates a dichotomy between `atom` and `cons`, while the latter one between `atom` and `list`. For me, the former makes more sense. – Svante Dec 13 '18 at 13:04
  • 1
    The traditional definition of an atom is anything which isn't a cons. That does not mean it's the only one which is possible, but it's what CL uses, and it goes back (at least) to Lisp 1.5. –  Dec 13 '18 at 14:56
  • 1
    I don’t think the [tag:language-lawer] tag is appropriate here, since TLS is not a standard by any means, and the notion of an “atom” is not defined in any Scheme standard. – Alexis King Dec 13 '18 at 16:26
  • @AlexisKing I was about to be annoyed by your meta-lawyering (plenty of real-life laws aren't explicitly written), but I just realised you were the speaker in the excellent Hackett talk at Strange Loop I was watching in the other tab. – Tumok A. Byrd Dec 17 '18 at 15:07

3 Answers3

2

lat is assumed to be a list of atoms at that point in the book.

If it's not empty, by definition it contains some atoms in it.

It's not about Lisp, it's about the book's presentation.

Will Ness
  • 70,110
  • 9
  • 98
  • 181
1

I think lat indicates list of atoms. Thus if lat is not null?, then it needs to contain at least one atom.

There is a procedure called lat? defined as such:

(define lat?
  (lambda (l)
    (cond
      ((null? l) #t)
      ((atom? (car l)) 
       (lat? (cdr l)))
      (else #f))))

(lat? '(()) ; ==> #f so by definition '(()) is not a lat and thus the statement does not apply to that list.

A list can contain any type of elements, including empty and other lists, both which are not atoms. lat is a restricted to a flat list with only atomic elements.

Sylwester
  • 47,942
  • 4
  • 47
  • 79
1

As a concept an “atom” is something that can not be broken into smaller parts. A number 42 is an atom, a list (42 43) is not an atom since it contains two smaller parts (namely the numbers 42 and 43). Since an empty list does not contain any smaller parts, it is by this logic an atom.

Now let’s attempt to implement an atom? predicate, that determines whether it’s input is an atom.

(define (atom? x)
  (cond
     [(number? x) #t]
     [(symbol? x) #t]
     [(char? x)   #t]
     ...
     [else #f]))

Here the ... needs to be replaced with a test for every atomic data type supported by the implementation. This can potentially be a long list. In order to avoid this, we can try to be clever:

(define (atom? x)
  (not (list? x)))

This will correctly return false for non-empty lists, and true for numbers, characters etc. However it will return false for the empty list.

Since it is up to the authors of the book to define the term “atom” (the word does not appear in the language standard) they might have opted for the above simple definition.

Note that the definition as non-list is misleading when the language contains other compound data structures such as vectors and structures. If I recall correctly the only compound data structure discussed in the book is lists.

soegaard
  • 30,661
  • 4
  • 57
  • 106