concept-arrays.tex 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. % -*- Mode: TeX -*-
  2. \beginsubsection{Array Elements}
  3. \DefineSection{ArrayElements}
  4. An \term{array} contains a set of \term{objects} called \term{elements}
  5. that can be referenced individually according to a rectilinear coordinate system.
  6. \beginsubsubsection{Array Indices}
  7. %% 2.5.0 5
  8. An \term{array} \term{element} is referred to by a (possibly empty) series of indices.
  9. The length of the series must equal the \term{rank} of the \term{array}.
  10. \issue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM}
  11. Each index must be a non-negative \term{fixnum}
  12. \endissue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM}
  13. %strictly
  14. less than the corresponding \term{array} \term{dimension}.
  15. \term{Array} indexing is zero-origin.
  16. \endsubsubsection%{Array Indices}
  17. \beginsubsubsection{Array Dimensions}
  18. An axis of an \term{array} is called a \newterm{dimension}.
  19. Each \term{dimension} is a non-negative
  20. \issue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM}
  21. \term{fixnum};
  22. \endissue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM}
  23. if any dimension of an \term{array} is zero, the \term{array} has no elements.
  24. % Maybe this part isn't in glossary...I just moved it from somewhere else per
  25. % suggestion of Barmar. -kmp 14-Jan-92
  26. It is permissible for a \term{dimension} to be zero,
  27. in which case the \term{array} has no elements,
  28. and any attempt to \term{access} an \term{element}
  29. is an error. However, other properties of the \term{array},
  30. such as the \term{dimensions} themselves, may be used.
  31. \beginsubsubsubsection{Implementation Limits on Individual Array Dimensions}
  32. An \term{implementation} may impose a limit on \term{dimensions} of an \term{array},
  33. but there is a minimum requirement on that limit. \Seevar{array-dimension-limit}.
  34. \endsubsubsubsection%{Implementation Limits on Individual Array Dimensions}
  35. \endsubsubsection%{Array Dimensions}
  36. \beginsubsubsection{Array Rank}
  37. %% 2.5.0 3
  38. %% 2.5.0 4
  39. An \term{array} can have any number of \term{dimensions} (including zero).
  40. The number of \term{dimensions} is called the \newterm{rank}.
  41. If the rank of an \term{array} is zero then the \term{array} is said to have
  42. no \term{dimensions}, and the product of the dimensions (see \funref{array-total-size})
  43. is then 1; a zero-rank \term{array} therefore has a single element.
  44. \beginsubsubsubsection{Vectors}
  45. An \term{array} of \term{rank} one (\ie a one-dimensional \term{array})
  46. is called a \newterm{vector}.
  47. \beginsubsubsubsubsection{Fill Pointers}
  48. A \newterm{fill pointer} is a non-negative \term{integer} no
  49. larger than the total number of \term{elements} in a \term{vector}.
  50. Not all \term{vectors} have \term{fill pointers}.
  51. \Seefuns{make-array} and \funref{adjust-array}.
  52. An \term{element} of a \term{vector} is said to be \newterm{active} if it has
  53. an index that is greater than or equal to zero,
  54. but less than the \term{fill pointer} (if any).
  55. For an \term{array} that has no \term{fill pointer},
  56. all \term{elements} are considered \term{active}.
  57. %% 17.5.0 4
  58. Only \term{vectors} may have \term{fill pointers};
  59. multidimensional \term{arrays} may not.
  60. A multidimensional \term{array} that is displaced to a \term{vector}
  61. that has a \term{fill pointer} can be created.
  62. \endsubsubsubsubsection%{Fill Pointers}
  63. \endsubsubsubsection%{Vectors}
  64. \beginsubsubsubsection{Multidimensional Arrays}
  65. \beginsubsubsubsubsection{Storage Layout for Multidimensional Arrays}
  66. %% 2.5.0 8
  67. Multidimensional \term{arrays} store their components in row-major order;
  68. that is, internally a multidimensional \term{array} is stored as a
  69. one-dimensional \term{array}, with the multidimensional index sets
  70. ordered lexicographically, last index varying fastest.
  71. \endsubsubsubsubsection%{Storage Layout for Multidimensional Arrays}
  72. \beginsubsubsubsubsection{Implementation Limits on Array Rank}
  73. An \term{implementation} may impose a limit on the \term{rank} of an \term{array},
  74. but there is a minimum requirement on that limit. \Seevar{array-rank-limit}.
  75. \endsubsubsubsubsection%{Implementation Limits on Array Rank}
  76. \endsubsubsubsection%{Multidimensional Arrays}
  77. \endsubsubsection%{Array Rank}
  78. \endsubsection%{Array Elements}
  79. \beginsubsection{Specialized Arrays}
  80. %% 17.0.0 4
  81. An \term{array} can be a \term{general} \term{array},
  82. meaning each \term{element} may be any \term{object},
  83. or it may be a \term{specialized} \term{array},
  84. meaning that each \term{element} must be of a restricted \term{type}.
  85. The phrasing ``an \term{array} \term{specialized} to \term{type} \metavar{type}''
  86. is sometimes used to emphasize the \term{element type} of an \term{array}.
  87. This phrasing is tolerated even when the \metavar{type} is \typeref{t},
  88. even though an \term{array} \term{specialized} to \term{type} \term{t}
  89. is a \term{general} \term{array}, not a \term{specialized} \term{array}.
  90. \Thenextfigure\ lists some \term{defined names} that are applicable to \term{array}
  91. creation, \term{access}, and information operations.
  92. %% Added ARRAY-DISPLACEMENT per Tom Shepard. (X3J13 approved: May 4-5, 1994)
  93. %% -kmp 9-May-94
  94. \displaythree{General Purpose Array-Related Defined Names}{
  95. adjust-array&array-has-fill-pointer-p&make-array\cr
  96. adjustable-array-p&array-in-bounds-p&svref\cr
  97. aref&array-rank&upgraded-array-element-type\cr
  98. array-dimension&array-rank-limit&upgraded-complex-part-type\cr
  99. array-dimension-limit&array-row-major-index&vector\cr
  100. array-dimensions&array-total-size&vector-pop\cr
  101. array-displacement&array-total-size-limit&vector-push\cr
  102. array-element-type&fill-pointer&vector-push-extend\cr
  103. }
  104. \beginsubsubsection{Array Upgrading}
  105. \DefineSection{ArrayUpgrading}
  106. \issue{ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS:UNIFY-UPGRADING}
  107. % Some of the following was transplanted from the description
  108. % of UPGRADED-ARRAY-ELEMENT-TYPE. Consider also stealing from
  109. % SUBTYPEP and TYPEP.
  110. The \newterm{upgraded array element type} of a \term{type} $T\sub 1$
  111. is a \term{type} $T\sub 2$ that is a \term{supertype} of $T\sub 1$
  112. and that is used instead of $T\sub 1$ whenever $T\sub 1$
  113. is used as an \term{array element type}
  114. for object creation or type discrimination.
  115. During creation of an \term{array},
  116. the \term{element type} that was requested
  117. is called the \newterm{expressed array element type}.
  118. The \term{upgraded array element type} of the \term{expressed array element type}
  119. becomes the \newterm{actual array element type} of the \term{array} that is created.
  120. %!!! Barmar thinks this should be removed.
  121. \term{Type} \term{upgrading} implies a movement upwards in the type hierarchy lattice.
  122. A \term{type} is always a \term{subtype} of its \term{upgraded array element type}.
  123. Also, if a \term{type} $T\sub x$ is a \term{subtype} of another \term{type} $T\sub y$,
  124. then
  125. the \term{upgraded array element type} of $T\sub x$
  126. must be a \term{subtype} of
  127. the \term{upgraded array element type} of $T\sub y$.
  128. Two \term{disjoint} \term{types} can be \term{upgraded} to the same \term{type}.
  129. The \term{upgraded array element type} $T\sub 2$ of a \term{type} $T\sub 1$
  130. is a function only of $T\sub 1$ itself;
  131. that is, it is independent of any other property of the \term{array}
  132. for which $T\sub 2$ will be used,
  133. such as \term{rank}, \term{adjustability}, \term{fill pointers}, or displacement.
  134. %% This next sentence is interesting, but is just Rationale, so is omitted.
  135. % The reason \term{rank} is included is because it would not
  136. % be consistently possible to displace \term{arrays} to those of differing
  137. % \term{rank} otherwise.
  138. \Thefunction{upgraded-array-element-type}
  139. can be used by \term{conforming programs} to predict how the \term{implementation}
  140. will \term{upgrade} a given \term{type}.
  141. \endissue{ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS:UNIFY-UPGRADING}
  142. \endsubsubsection%{Array Upgrading}
  143. \beginsubsubsection{Required Kinds of Specialized Arrays}
  144. \DefineSection{RequiredSpecializedArrays}
  145. %% 17.0.0 5
  146. \term{Vectors} whose \term{elements} are restricted to \term{type}
  147. \issue{CHARACTER-PROPOSAL:2-3-2}
  148. \typeref{character} or a \term{subtype} of \typeref{character}
  149. \endissue{CHARACTER-PROPOSAL:2-3-2}
  150. are called \newtermidx{strings}{string}.
  151. \term{Strings} are \oftype{string}.
  152. %% 18.0.0 7
  153. %% 18.0.0 4
  154. \Thenextfigure\ lists some \term{defined names} related to \term{strings}.
  155. \term{Strings} are \term{specialized} \term{arrays}
  156. and might logically have been included in this chapter.
  157. However, for purposes of readability
  158. most information about \term{strings} does not appear in this chapter;
  159. see instead \chapref\Strings.
  160. %% 18.0.0 5
  161. %% paragraph duplicated in descriptions of string-equal and string=
  162. %% 18.0.0 6
  163. %% paragraph duplicated in description of stringp
  164. \displaythree{Operators that Manipulate Strings}{
  165. char&string-equal&string-upcase\cr
  166. make-string&string-greaterp&string{\tt /=}\cr
  167. nstring-capitalize&string-left-trim&string{\tt <}\cr
  168. nstring-downcase&string-lessp&string{\tt <=}\cr
  169. nstring-upcase&string-not-equal&string{\tt =}\cr
  170. schar&string-not-greaterp&string{\tt >}\cr
  171. string&string-not-lessp&string{\tt >=}\cr
  172. string-capitalize&string-right-trim&\cr
  173. string-downcase&string-trim&\cr
  174. }
  175. \term{Vectors} whose \term{elements} are restricted to \term{type}
  176. \typeref{bit} are called \newtermidx{bit vectors}{bit vector}.
  177. \term{Bit vectors} are \oftype{bit-vector}.
  178. \Thenextfigure\ lists some \term{defined names} for operations on \term{bit arrays}.
  179. \displaythree{Operators that Manipulate Bit Arrays}{
  180. bit&bit-ior&bit-orc2\cr
  181. bit-and&bit-nand&bit-xor\cr
  182. bit-andc1&bit-nor&sbit\cr
  183. bit-andc2&bit-not&\cr
  184. bit-eqv&bit-orc1&\cr
  185. }
  186. \endsubsubsection%{Required Kinds of Specialized Arrays}
  187. \endsubsection%{Specialized Arrays}