Does a non-null Scheme list contain at least one atom?

scheme append to list
scheme reverse list
scheme null?
scheme flatten list
scheme list length
scheme sublist
scheme empty list
scheme iterate through list

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.)

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.

lisp - Does a non-null Scheme list contain at least one atom?, 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. Cdr of that first element is a one-element list, that is, all but the English word that's the first element of the pairing. What we want isn't the one-element list but rather its only element, the French word, which is its car. This car of cdr of car business is pretty lengthy and awkward. But Scheme gives us a way to say it succinctly:

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.

Does a non-null Scheme list contain at least one atom?, 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. Scheme lists can contain items of different types: (1 1.5 x (a) ((7))) Here are some important functions that operate on lists: length-- length of a list equal?-- test if two lists are equal (recursively) car-- first element of a list cdr-- rest of a list cons-- make a new list cell (a.k.a. cons cell) list-- make a list

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.

Simply Scheme: Introducing Computer Science ch 17: Lists, The definition of "sentence" is not self-referential, because the elements of a [1] The function to select the portion of a list containing all but the first element (​define (praise flavors) (if (null? flavors) '() (cons (se (car flavors) '(is In this example, you must invoke increasing? with at least one argument; that argument will be  RFC 4287 Atom Format December 2005 The following child elements are defined by this specification (note that the presence of some of these elements is required): o atom:feed elements MUST contain one or more atom:author elements, unless all of the atom:feed element's child atom:entry elements contain at least one atom:author element. o atom

MIT Scheme Reference, The empty list is in X . If list is in X , then any pair whose cdr field contains list is also in The empty list is a special object of its own type (it is not a pair); it has no Any object satisfying this predicate will also satisfy exactly one of pair? or null? list-processing procedures can be expressed in terms of fold-right , at least for  unzip1 takes a list of lists, where every list must contain at least one element, and returns a list containing the initial element of each such list. That is, it returns (map car lists) . unzip2 takes a list of lists, where every list must contain at least two elements, and returns two values: a list of the first elements, and a list of the

[PDF] CSE 142 Section 5.5 (sample midterm), We are giving you longer practice problem sets so you will have lots values in the list are non-negative and that the list contains at least one odd value. Define a Scheme procedure called occurrences that takes a value and a list as The method should return null if called on an empty array or if the array is not in sorted  Pairs are not mutable (but see Mutable Pairs and Lists). A list is recursively defined: it is either the constant null, or it is a pair whose second value is a list. A list can be used as a single-valued sequence (see Sequences). The elements of the list serve as elements of the sequence. See also in-list.

CSE 341 -- Scheme Basics, Lisp dialect; usually interpreted (but good compilers exist) Case is generally not significant (except in characters or strings). Note that Perhaps the single most important built in data type in Scheme is the list. Because Scheme will treat the atom elmer as a variable name and try to look for its binding, which it won't find. In 1925, chemist Frederick Soddy found that some elements in the periodic table had more than one kind of atom. For example, any atom with 2 protons should be a helium atom. Usually, a helium nucleus also contains two neutrons. However, some helium atoms have only one neutron.

Comments
  • 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.
  • 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.
  • I don’t think the 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.
  • @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.
  • although (list? '(1 . 2)) returns #f, but '(1 . 2) is certainly not an atom ...
  • I don't remember. :)