diff options
Diffstat (limited to 'lispref/sequences.texi')
-rw-r--r-- | lispref/sequences.texi | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/lispref/sequences.texi b/lispref/sequences.texi index 153975947b9..c1e7f3dc2d0 100644 --- a/lispref/sequences.texi +++ b/lispref/sequences.texi @@ -13,33 +13,33 @@ sequence, any vector is a sequence, and any string is a sequence. The common property that all sequences have is that each is an ordered collection of elements. - An @dfn{array} is a single primitive object directly containing all -its elements. Therefore, all the elements are accessible in constant -time. The length of an existing array cannot be changed. Both strings -and vectors are arrays. A list is a sequence of elements, but it is not -a single primitive object; it is made of cons cells, one cell per -element. Therefore, elements farther from the beginning of the list -take longer to access, but it is possible to add elements to the list or -remove elements. + An @dfn{array} is a single primitive object that has a slot for each +elements. All the elements are accessible in constant time, but the +length of an existing array cannot be changed. Both strings and vectors +are arrays. + + A list is a sequence of elements, but it is not a single primitive +object; it is made of cons cells, one cell per element. Finding the +@var{n}th element requires looking through @var{n} cons cells, so +elements farther from the beginning of the list take longer to access. +But it is possible to add elements to the list, or remove elements. The following diagram shows the relationship between these types: @example @group - ___________________________________ - | | - | Sequence | - | ______ ______________________ | - | | | | | | - | | List | | Array | | - | | | | ________ _______ | | - | |______| | | | | | | | - | | | String | | Vector| | | - | | |________| |_______| | | - | |______________________| | - |___________________________________| - -@center @r{The relationship between sequences, arrays, and vectors} + ___________________________________ + | | + | Sequence | + | ______ ______________________ | + | | | | | | + | | List | | Array | | + | | | | ________ _______ | | + | |______| | | | | | | | + | | | String | | Vector| | | + | | |________| |_______| | | + | |______________________| | + |___________________________________| @end group @end example @@ -50,7 +50,8 @@ elements of strings are all characters. * Sequence Functions:: Functions that accept any kind of sequence. * Arrays:: Characteristics of arrays in Emacs Lisp. * Array Functions:: Functions specifically for arrays. -* Vectors:: Functions specifically for vectors. +* Vectors:: Special characteristics of Emacs Lisp vectors. +* Vector Functions:: Functions specifically for vectors. @end menu @node Sequence Functions @@ -199,7 +200,7 @@ sequence. @section Arrays @cindex array - An @dfn{array} object refers directly to a number of other Lisp + An @dfn{array} object has slots that hold a number of other Lisp objects, called the elements of the array. Any element of an array may be accessed in constant time. In contrast, an element of a list requires access time that is proportional to the position of the element @@ -208,8 +209,8 @@ in the list. When you create an array, you must specify how many elements it has. The amount of space allocated depends on the number of elements. Therefore, it is impossible to change the size of an array once it is -created. You cannot add or remove elements. However, you can replace -an element with a different value. +created; you cannot add or remove elements. However, you can replace an +element with a different value. Emacs defines two types of array, both of which are one-dimensional: @dfn{strings} and @dfn{vectors}. A vector is a general array; its @@ -218,7 +219,7 @@ elements must be characters (i.e., integers between 0 and 255). Each type of array has its own read syntax. @xref{String Type}, and @ref{Vector Type}. - Both kinds of arrays share these characteristics: + Both kinds of array share these characteristics: @itemize @bullet @item @@ -325,8 +326,8 @@ If @var{array} is a string and @var{object} is not a character, a @end defun @defun fillarray array object -This function fills the array @var{array} with pointers to @var{object}, -replacing any previous values. It returns @var{array}. +This function fills the array @var{array} with @var{object}, so that +each element of @var{array} is @var{object}. It returns @var{array}. @example @group @@ -369,10 +370,10 @@ a vector in it. In Emacs Lisp, the indices of the elements of a vector start from zero and count up from there. - Vectors are printed with square brackets surrounding the elements -in their order. Thus, a vector containing the symbols @code{a}, -@code{b} and @code{c} is printed as @code{[a b c]}. You can write -vectors in the same way in Lisp input. + Vectors are printed with square brackets surrounding the elements. +Thus, a vector whose elements are the symbols @code{a}, @code{b} and +@code{a} is printed as @code{[a b a]}. You can write vectors in the +same way in Lisp input. A vector, like a string or a number, is considered a constant for evaluation: the result of evaluating it is the same vector. This does @@ -392,6 +393,9 @@ not evaluate or even examine the elements of the vector. @end group @end example +@node Vector Functions +@section Functions That Operate on Vectors + Here are some functions that relate to vectors: @defun vectorp object |