home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!usc!cs.utexas.edu!sun-barr!olivea!mintaka.lcs.mit.edu!gateway
- From: wkf@stony-brook.scrc.symbolics.com (William K. Foster)
- Newsgroups: comp.lang.lisp
- Subject: Improper lists
- Message-ID: <19930108174830.1.WKF@DJINN.SCRC.Symbolics.COM>
- Date: 8 Jan 93 17:56:54 GMT
- Sender: news@mintaka.lcs.mit.edu
- Organization: LCS news/mail gateway
- Lines: 53
- X-Unparseable-Date: Fri
-
- 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
-