home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / lisp / 3210 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  2.2 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!usc!cs.utexas.edu!sun-barr!olivea!mintaka.lcs.mit.edu!gateway
  2. From: wkf@stony-brook.scrc.symbolics.com (William K. Foster)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Improper lists
  5. Message-ID: <19930108174830.1.WKF@DJINN.SCRC.Symbolics.COM>
  6. Date: 8 Jan 93 17:56:54 GMT
  7. Sender: news@mintaka.lcs.mit.edu
  8. Organization: LCS news/mail gateway
  9. Lines: 53
  10. X-Unparseable-Date: Fri
  11.  
  12. I am trying to clarify what the ANSI spec says.
  13.  
  14. 1list 2n.0 1. a chain of 2conses 0in which the 2car0 of each 2cons0 is an 2element
  15. 0of the 2list0, and the 2cdr0 of each cons is either the next link in the
  16. chain or a terminating 2atom.0 See also 2proper list0, 2dotted list0, or
  17. 2circular list0. 2. the 2type 0that is the union of 1null 0and1 cons0.
  18.  
  19. This definition does not state whether an empty chain of2 conses0 is a
  20. 2list0. An empty chain must be a 2list 0in order for2 nil0 to be a2 list0.
  21. However, using the same reasoning, all 2atoms0 are2 lists0, 2nil0 being a
  22. 2proper list 0and all other 2atoms0 being 2improper lists0.
  23.  
  24.  
  25. 1nth0 is defined to take a second argument which is a2 list0.
  26.  
  27. If the length of 3list 0is not greater then3 n0, then the result is1 nil0.
  28.  
  29. 1length2 n0. (of a2 sequence0) the number of 2elements 0in the2 sequence0.
  30.  
  31. 1element2 n0. 1. (of a2 list0) an 2object 0that is the 2car 0of one of the2 conses
  32. 0that comprise the2 list0.
  33.  
  34. Given these defintions the following should be true:
  35.  
  36. (nth 'foo 0)     => nil
  37. (nth 17 23)      => nil
  38. (nth '(a . b) 1) => nil
  39.  
  40.  
  41. Conversely:
  42.  
  43. 1nthcdr0 returns the3 n0th successive 2cdr 0of3 list0.
  44.  
  45. The functions 1car 0and 1cdr 0should signal 1type-error0 if they receive an
  46. argument which is not a2 list0.
  47.  
  48. This would imply that 2atoms 0are not2 lists0. (as one would expect)
  49.  
  50. Therefore 1nthcdr0 signals 1type-error0 if 3n0 would go off the end of a
  51. 2dotted list0.
  52.  
  53. Since 1nth0 does handle 2dotted lists0 as stated above
  54.  
  55. (nth n dotted-list)  (car (nthcdr n dotted-list))
  56.  
  57. where n is greater than the number of elements in dotted-list.
  58.  
  59. Also in the definitions for 1first, second, .., tenth
  60.  
  61. 0(fifth x)  (nth 4 x)
  62.  
  63. Given the definition of 1nth 0as interpreted here, this is only true when
  64. x is a 2proper list0 or an 2improper list0 with more than 42 elements
  65.