From: William K. Foster
Subject: Improper lists
Date: 
Message-ID: <19930108174830.1.WKF@DJINN.SCRC.Symbolics.COM>
I am trying to clarify what the ANSI spec says.

1list 2n.0 1. a chain of 2conses 0in which the 2car0 of each 2cons0 is an 2element
0of the 2list0, and the 2cdr0 of each cons is either the next link in the
chain or a terminating 2atom.0 See also 2proper list0, 2dotted list0, or
2circular list0. 2. the 2type 0that is the union of 1null 0and1 cons0.

This definition does not state whether an empty chain of2 conses0 is a
2list0. An empty chain must be a 2list 0in order for2 nil0 to be a2 list0.
However, using the same reasoning, all 2atoms0 are2 lists0, 2nil0 being a
2proper list 0and all other 2atoms0 being 2improper lists0.


1nth0 is defined to take a second argument which is a2 list0.

If the length of 3list 0is not greater then3 n0, then the result is1 nil0.

1length2 n0. (of a2 sequence0) the number of 2elements 0in the2 sequence0.

1element2 n0. 1. (of a2 list0) an 2object 0that is the 2car 0of one of the2 conses
0that comprise the2 list0.

Given these defintions the following should be true:

(nth 'foo 0)     => nil
(nth 17 23)      => nil
(nth '(a . b) 1) => nil


Conversely:

1nthcdr0 returns the3 n0th successive 2cdr 0of3 list0.

The functions 1car 0and 1cdr 0should signal 1type-error0 if they receive an
argument which is not a2 list0.

This would imply that 2atoms 0are not2 lists0. (as one would expect)

Therefore 1nthcdr0 signals 1type-error0 if 3n0 would go off the end of a
2dotted list0.

Since 1nth0 does handle 2dotted lists0 as stated above

(nth n dotted-list)  (car (nthcdr n dotted-list))

where n is greater than the number of elements in dotted-list.

Also in the definitions for 1first, second, .., tenth

0(fifth x)  (nth 4 x)

Given the definition of 1nth 0as interpreted here, this is only true when
x is a 2proper list0 or an 2improper list0 with more than 42 elements

From: Bruce R. Miller
Subject: Re: Improper lists
Date: 
Message-ID: <2935524009@ARTEMIS.cam.nist.gov>
In article <····················@DJINN.SCRC.Symbolics.COM>, William K. Foster writes:
> I am trying to clarify what the ANSI spec says.
> 
> 1list 2n.0 1. a chain of 2conses 0in which the 2car0 of each 2cons0 is an 2element

Hey, you forgot the
  Character-Type-Mappings:
header!!!!

Help, Epsilons!  I'm going blind!!!
Arghhh!!!
From: Barry Margolin
Subject: Re: Improper lists
Date: 
Message-ID: <1in9pkINNe50@early-bird.think.com>
In article <····················@DJINN.SCRC.Symbolics.COM> ···@stony-brook.scrc.symbolics.com (William K. Foster) writes:
>This definition does not state whether an empty chain of conses is a
>list. An empty chain must be a list in order for nil to be a list.
>However, using the same reasoning, all atoms are lists, nil being a
>proper list and all other atoms being improper lists.

Given the definitions as they're currently written, you're correct: all
objects are lists (well, it *is* a "list processing" language :-).  I don't
think this was the original intent, though; I'm looking into getting the
definition of "dotted list" changed to require at least one cons (and refer
to this in the definition of "list").

Note also that there are two definitions of "list" in the glossary.  The
second definition is objects of type (OR CONS NULL), and atoms aren't lists
according to that.  The first definition describes the concept of lists,
while the second one describes the type list.  Since the first definition
is currently useless for discrimination, we may decide that any use of the
term for descrimination must intend the second definition.

>nth is defined to take a second argument which is a list.

This isn't a problem, even without the above clarifications.  The beginning
of the Conses chapter says:

  "Except as explicitly specified otherwise, any \term{standardized}
  \term{function} that takes a \term{parameter} that required to be a
  \term{list} should be prepared to signal an error \oftype{type-error} if
  the \term{value} received is a \term{dotted list}."

A problem with this is that it permits implementations to signal an error
when the argument is a dotted list, even if it doesn't need to access the
end of the list; for instance, (NTH '(A . B) 0) could signal an error (the
"should be prepared to signal" phrase allows an implementation to omit
checking, but it doesn't prevent checking).  Therefore, there's been a
proposal to change many of these functions to allow dotted list arguments.
In that case my clarifications would solve the problem of (NTH <atom> N)
being allowed.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar