concept-conses.tex 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. % -*- Mode: TeX -*-
  2. A \newterm{cons} is a compound data \term{object}
  3. having two components called the \term{car} and the \term{cdr}.
  4. \displaythree{Some defined names relating to conses.}{
  5. car&cons&rplacd\cr
  6. cdr&rplaca&\cr
  7. }
  8. Depending on context, a group of connected \term{conses} can be viewed
  9. in a variety of different ways. A variety of operations is provided to
  10. support each of these various views.
  11. \beginsubsection{Conses as Trees}
  12. A \newterm{tree} is a binary recursive data structure made up of
  13. \term{conses} and \term{atoms}:
  14. the \term{conses} are themselves also \term{trees}
  15. (sometimes called ``subtrees'' or ``branches''), and the \term{atoms}
  16. are terminal nodes (sometimes called \newterm{leaves}).
  17. Typically, the \term{leaves} represent data while the branches
  18. establish some relationship among that data.
  19. \displayfour{Some defined names relating to trees.}{
  20. caaaar&caddar&cdar&nsubst\cr
  21. caaadr&cadddr&cddaar&nsubst-if\cr
  22. caaar&caddr&cddadr&nsubst-if-not\cr
  23. caadar&cadr&cddar&nthcdr\cr
  24. caaddr&cdaaar&cdddar&sublis\cr
  25. caadr&cdaadr&cddddr&subst\cr
  26. caar&cdaar&cdddr&subst-if\cr
  27. cadaar&cdadar&cddr&subst-if-not\cr
  28. cadadr&cdaddr&copy-tree&tree-equal\cr
  29. cadar&cdadr&nsublis&\cr
  30. }
  31. \beginsubsubsection{General Restrictions on Parameters that must be Trees}
  32. \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  33. Except as explicitly stated otherwise,
  34. for any \term{standardized} \term{function} that takes a \term{parameter}
  35. that is required to be a \term{tree},
  36. the consequences are undefined
  37. if that \term{tree} is circular.
  38. \endissue{DOTTED-LIST-ARGUMENTS:CLARIFY}
  39. \endsubsubsection%{General Restrictions on Parameters that must be Trees}
  40. \endsubsection%{Conses as Trees}
  41. \beginsubsection{Conses as Lists}
  42. A \newterm{list} is a chain of \term{conses} in which the \term{car} of each
  43. \term{cons} is an \term{element} of the \term{list},
  44. and the \term{cdr} of each \term{cons} is either the next
  45. link in the chain or a terminating \term{atom}.
  46. A \newterm{proper list} is a \term{list} terminated by the \term{empty list}.
  47. The \term{empty list} is a \term{proper list}, but is not a \term{cons}.
  48. An \newterm{improper list} is a \term{list} that is not a \term{proper list};
  49. that is, it is a \term{circular list} or a \term{dotted list}.
  50. A \newterm{dotted list} is a \term{list} that has a terminating \term{atom}
  51. that is not the \term{empty list}. A \term{non-nil} \term{atom} by itself
  52. is not considered to be a \term{list} of any kind---not even a \term{dotted list}.
  53. A \newterm{circular list} is a chain of \term{conses} that has no termination
  54. because some \term{cons} in the chain is the \term{cdr} of a later \term{cons}.
  55. \displayfour{Some defined names relating to lists.}{
  56. append&last&nbutlast&rest\cr
  57. butlast&ldiff&nconc&revappend\cr
  58. copy-alist&list&ninth&second\cr
  59. copy-list&list*&nreconc&seventh\cr
  60. eighth&list-length&nth&sixth\cr
  61. endp&make-list&nthcdr&tailp\cr
  62. fifth&member&pop&tenth\cr
  63. first&member-if&push&third\cr
  64. fourth&member-if-not&pushnew&\cr
  65. }
  66. \beginsubsubsection{Lists as Association Lists}
  67. An \newterm{association list} is a \term{list} of \term{conses}
  68. representing an association of \term{keys} with \term{values},
  69. where the \term{car} of each \term{cons} is the \term{key}
  70. and the \term{cdr} is the \term{value} associated with that \term{key}.
  71. \displayfour{Some defined names related to assocation lists.}{
  72. acons&assoc-if&pairlis&rassoc-if\cr
  73. assoc&assoc-if-not&rassoc&rassoc-if-not\cr
  74. }
  75. \endsubsubsection%{Lists as Association Lists}
  76. \beginsubsubsection{Lists as Sets}
  77. \term{Lists} are sometimes viewed as sets by considering their elements
  78. unordered and by assuming there is no duplication of elements.
  79. \displayfour{Some defined names related to sets.}{
  80. adjoin&nset-difference&set-difference&union\cr
  81. intersection&nset-exclusive-or&set-exclusive-or&\cr
  82. nintersection&nunion&subsetp&\cr
  83. }
  84. \endsubsubsection%{Lists as Sets}
  85. \beginsubsubsection{General Restrictions on Parameters that must be Lists}
  86. %Barrett: This forces something like
  87. % \f{(MEMBER X '(X Y . Z))} to detect the \f{( . Z )}
  88. % in safe code even when it would not naturally be reached
  89. % by the search. We should soften this slightly.
  90. %KMP: Fixed.
  91. Except as explicitly specified otherwise,
  92. any \term{standardized} \term{function} that takes a \term{parameter}
  93. that is required to be a \term{list} should be prepared to signal
  94. an error \oftype{type-error} if the \term{value} received is a \term{dotted list}.
  95. % Sandra complained that this was only said a few places,
  96. % and needed to be said more.
  97. % This is a stopgap while we make sure we mean it everywhere.
  98. Except as explicitly specified otherwise,
  99. for any \term{standardized} \term{function} that takes a \term{parameter}
  100. that is required to be a \term{list},
  101. the consequences are undefined
  102. if that \term{list} is \term{circular}.
  103. \endsubsubsection%{General Restrictions on Parameters that must be Lists}
  104. \endsubsection%{Conses as Lists}