[plt-scheme] atom?

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Jan 11 15:17:09 EST 2006

Pierpaolo BERNARDI wrote:
> On Wed, 11 Jan 2006 17:54:50 +0100, Jens Axel Søgaard 
> <jensaxel at soegaard.net> wrote:
> 
>> I just fell over this in (lib "compat.ss")
>>
>>    (atom? v)      PROCEDURE
>>    Same as (not (pair? v)).
> 
> 
>> Wouldn't
>>
>> (define (atom? o)
>>    (or (void? o)
>>        (boolean? o)
>>        (number? 0)
>>        (char? o)
>>        (symbol? o)
>>        (keyword? o)
>>        (null? o)))
>>
>> be better?
> 
> 
> No. The first definition is what ATOM{P|?} means in every lisp 
> implementation since lisp 1.5 (and maybe before)

I had to dig up a LISP 1.5 manual.

The first mentioning of atoms is on page 1.

   1.1 Symbolic Expressions

   The most elementary type of S-expression is the atomic symbol.

   Definition: An atomic symbol is a string of no more than thirty
   numerals and capital letters; the first character must be a letter.

   Examples
   A
   APPLE
   PART2
   EXTRALONGSTRINGOFLETTERS
   A4B66XYZ2

   These symbols are called atomic because they are taken as a whole and
   are not capable of being split within LISP into individual characters,
   Thus A, B, and AB have no relation to each other except in so far as
   they are three distinct atomic symbols.

   All S-expressions are built out of atomic symbols and the punctuation
   marks ( , and . . The basic operation for forming S-expressions is to
   combine two of them to produce a larger one. From the two atomic
   symbols A1 and A2, one can form the S-expression (A1 . A2).

   Definition: An S-expression is either an atomic symbol or it is
   composed of these elements in the following order: a left parenthesis,
   an S-expression, a dot, an Sexpression, and a right parenthesis.


The rationale behind the word "atomic" is thus:

   These symbols are called atomic because they are taken as a whole and
   are not capable of being split within LISP into individual characters,

Hmm. What about vectors? Oh yes. There were no vectors in LISP 1.5.
There were arrays, but "(Nonlist arrays are reserved for future 
development~ of the LISP system.)".

Well, what about numbers then?

   Numbers are represented by a type of atomic symbol in LISP. This word
   consists of a word with -1 in the address, certain bits in the tag
   which specify that it is a number and what type it is, and a pointer
   to the number itself in the decrement of this word.

   Unlike atomic symbols, numbers are not stored uniquely.

Ok, so numbers are also atomic.

What about the empty list then?

   The atomic symbol NIL serves as a terminator for lists. The null list
   ( ) is identical to NIL. Lists may have sublists. The dot notation and
   the list notation may be used in the same S-expression,

So the empty list was an atom back then.


Perhaps the atom? in (lib "compat.ss") stems from the "Little LISPer"?

Richard Cobbe writes in

<http://groups.google.com/group/comp.lang.scheme/msg/c65b4e1852eda02d?hl=en&>

   I was going to respond with that, but I wasn't sure which edition of
   the book the OP was using.  The fact that he gives the title as _The
   Little LISPer_ indicates that he's not using 4ed.

   This is significant because the book's definition of atom? changed
   between 3ed and 4ed: IIRC, originally (atom? '()) ==> #t.


-- 
Jens Axel Søgaard




Posted on the users mailing list.