annotate lispref/sequences.texi @ 21314:7d4a55d38b2c

(tex-send-command): Return the process. (tex-start-tex): New function. (tex-region, tex-file): Use tex-start-tex. (tex-start-tex-marker): New variable. (tex-compilation-parse-errors): Completely rewritten. (tex-print): Reset or restart the subshell before using it.
author Richard M. Stallman <rms@gnu.org>
date Mon, 30 Mar 1998 04:21:52 +0000
parents 66d807bdc5b4
children 90da2489c498
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 @c -*-texinfo-*-
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 @c This is part of the GNU Emacs Lisp Reference Manual.
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 @c See the file elisp.texi for copying conditions.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 @setfilename ../info/sequences
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 @node Sequences Arrays Vectors, Symbols, Lists, Top
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 @chapter Sequences, Arrays, and Vectors
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 @cindex sequence
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 Recall that the @dfn{sequence} type is the union of three other Lisp
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 types: lists, vectors, and strings. In other words, any list is a
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 sequence, any vector is a sequence, and any string is a sequence. The
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 common property that all sequences have is that each is an ordered
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 collection of elements.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
16 An @dfn{array} is a single primitive object that has a slot for each
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
17 elements. All the elements are accessible in constant time, but the
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
18 length of an existing array cannot be changed. Strings and vectors are
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
19 the two types of arrays.
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
20
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
21 A list is a sequence of elements, but it is not a single primitive
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
22 object; it is made of cons cells, one cell per element. Finding the
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
23 @var{n}th element requires looking through @var{n} cons cells, so
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
24 elements farther from the beginning of the list take longer to access.
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
25 But it is possible to add elements to the list, or remove elements.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 The following diagram shows the relationship between these types:
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 @group
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
31 ___________________________________
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
32 | |
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
33 | Sequence |
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
34 | ______ ______________________ |
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
35 | | | | | |
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
36 | | List | | Array | |
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
37 | | | | ________ _______ | |
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
38 | |______| | | | | | | |
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
39 | | | Vector | | String| | |
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
40 | | |________| |_______| | |
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
41 | |______________________| |
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
42 |___________________________________|
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 The elements of vectors and lists may be any Lisp objects. The
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 elements of strings are all characters.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 @menu
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 * Sequence Functions:: Functions that accept any kind of sequence.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 * Arrays:: Characteristics of arrays in Emacs Lisp.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 * Array Functions:: Functions specifically for arrays.
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
53 * Vectors:: Special characteristics of Emacs Lisp vectors.
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
54 * Vector Functions:: Functions specifically for vectors.
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
55 * Char-Tables:: How to work with char-tables.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
56 * Bool-Vectors:: How to work with bool-vectors.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 @end menu
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 @node Sequence Functions
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 @section Sequences
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 In Emacs Lisp, a @dfn{sequence} is either a list, a vector or a
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 string. The common property that all sequences have is that each is an
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ordered collection of elements. This section describes functions that
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 accept any kind of sequence.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 @defun sequencep object
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 Returns @code{t} if @var{object} is a list, vector, or
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 string, @code{nil} otherwise.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 @defun copy-sequence sequence
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 @cindex copying sequences
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 Returns a copy of @var{sequence}. The copy is the same type of object
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 as the original sequence, and it has the same elements in the same order.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 Storing a new element into the copy does not affect the original
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 @var{sequence}, and vice versa. However, the elements of the new
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 sequence are not copies; they are identical (@code{eq}) to the elements
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 of the original. Therefore, changes made within these elements, as
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 found via the copied sequence, are also visible in the original
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 sequence.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 If the sequence is a string with text properties, the property list in
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 the copy is itself a copy, not shared with the original's property
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 list. However, the actual values of the properties are shared.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 @xref{Text Properties}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 See also @code{append} in @ref{Building Lists}, @code{concat} in
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 @ref{Creating Strings}, and @code{vconcat} in @ref{Vectors}, for others
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ways to copy sequences.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (setq bar '(1 2))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 @result{} (1 2)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (setq x (vector 'foo bar))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 @result{} [foo (1 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (setq y (copy-sequence x))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 @result{} [foo (1 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (eq x y)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 @result{} nil
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (equal x y)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (eq (elt x 1) (elt y 1))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;; @r{Replacing an element of one sequence.}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (aset x 0 'quux)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 x @result{} [quux (1 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 y @result{} [foo (1 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; @r{Modifying the inside of a shared element.}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (setcar (aref x 1) 69)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 x @result{} [quux (69 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 y @result{} [foo (69 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 @defun length sequence
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 @cindex string length
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 @cindex list length
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 @cindex vector length
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 @cindex sequence length
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 Returns the number of elements in @var{sequence}. If @var{sequence} is
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 a cons cell that is not a list (because the final @sc{cdr} is not
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 @code{nil}), a @code{wrong-type-argument} error is signaled.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
145 @xref{List Elements}, for the related function @code{safe-list}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
146
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (length '(1 2 3))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 @result{} 3
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (length ())
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 @result{} 0
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (length "foobar")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 @result{} 6
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (length [1 2 3])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 @result{} 3
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 @defun elt sequence index
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 @cindex elements of sequences
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 This function returns the element of @var{sequence} indexed by
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 @var{index}. Legitimate values of @var{index} are integers ranging from
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 0 up to one less than the length of @var{sequence}. If @var{sequence}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 is a list, then out-of-range values of @var{index} return @code{nil};
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 otherwise, they trigger an @code{args-out-of-range} error.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (elt [1 2 3 4] 2)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 @result{} 3
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (elt '(1 2 3 4) 2)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 @result{} 3
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (char-to-string (elt "1234" 2))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 @result{} "3"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (elt [1 2 3 4] 4)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 @error{}Args out of range: [1 2 3 4], 4
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (elt [1 2 3 4] -1)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 @error{}Args out of range: [1 2 3 4], -1
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
198 This function generalizes @code{aref} (@pxref{Array Functions}) and
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
199 @code{nth} (@pxref{List Elements}).
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 @node Arrays
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 @section Arrays
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 @cindex array
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
206 An @dfn{array} object has slots that hold a number of other Lisp
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 objects, called the elements of the array. Any element of an array may
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 be accessed in constant time. In contrast, an element of a list
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 requires access time that is proportional to the position of the element
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 in the list.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 When you create an array, you must specify how many elements it has.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 The amount of space allocated depends on the number of elements.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 Therefore, it is impossible to change the size of an array once it is
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
215 created; you cannot add or remove elements. However, you can replace an
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
216 element with a different value.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 Emacs defines two types of array, both of which are one-dimensional:
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 @dfn{strings} and @dfn{vectors}. A vector is a general array; its
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 elements can be any Lisp objects. A string is a specialized array; its
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 elements must be characters (i.e., integers between 0 and 255). Each
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 type of array has its own read syntax. @xref{String Type}, and
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 @ref{Vector Type}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
225 Both kinds of array share these characteristics:
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 @itemize @bullet
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 The first element of an array has index zero, the second element has
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 index 1, and so on. This is called @dfn{zero-origin} indexing. For
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 example, an array of four elements has indices 0, 1, 2, @w{and 3}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 The elements of an array may be referenced or changed with the functions
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 @code{aref} and @code{aset}, respectively (@pxref{Array Functions}).
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 @end itemize
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
238 In principle, if you wish to have an array of text characters, you
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
239 could use either a string or a vector. In practice, we always choose
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
240 strings for such applications, for four reasons:
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 @itemize @bullet
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 They occupy one-fourth the space of a vector of the same elements.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 Strings are printed in a way that shows the contents more clearly
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
248 as text.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 Strings can hold text properties. @xref{Text Properties}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 Many of the specialized editing and I/O facilities of Emacs accept only
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 strings. For example, you cannot insert a vector of characters into a
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 buffer the way you can insert a string. @xref{Strings and Characters}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 @end itemize
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
259 By contrast, for an array of keyboard input characters (such as a key
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
260 sequence), a vector may be necessary, because many keyboard input
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
261 characters are outside the range that will fit in a string. @xref{Key
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
262 Sequence Input}.
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
263
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 @node Array Functions
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 @section Functions that Operate on Arrays
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
267 In this section, we describe the functions that accept all types of
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
268 arrays.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 @defun arrayp object
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
271 This function returns @code{t} if @var{object} is an array (i.e., a
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
272 vector, a string, a bool-vector or a char-table).
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (arrayp [a])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (arrayp "asdf")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 @defun aref array index
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 @cindex array elements
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 This function returns the @var{index}th element of @var{array}. The
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 first element is at index zero.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (setq primes [2 3 5 7 11 13])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 @result{} [2 3 5 7 11 13]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (aref primes 4)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 @result{} 11
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (elt primes 4)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 @result{} 11
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (aref "abcdefg" 1)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 @result{} 98 ; @r{@samp{b} is @sc{ASCII} code 98.}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 See also the function @code{elt}, in @ref{Sequence Functions}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 @defun aset array index object
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 This function sets the @var{index}th element of @var{array} to be
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 @var{object}. It returns @var{object}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (setq w [foo bar baz])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 @result{} [foo bar baz]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (aset w 0 'fu)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 @result{} fu
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 w
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 @result{} [fu bar baz]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (setq x "asdfasfd")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 @result{} "asdfasfd"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (aset x 3 ?Z)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 @result{} 90
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 x
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 @result{} "asdZasfd"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 If @var{array} is a string and @var{object} is not a character, a
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
333 @code{wrong-type-argument} error results. If @var{array} is a string
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
334 and @var{object} is character, but @var{object} does not use the same
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
335 number of bytes as the character currently stored in @code{(aref
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
336 @var{object} @var{index})}, that is also an error. @xref{Chars and
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
337 Bytes}.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 @defun fillarray array object
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
341 This function fills the array @var{array} with @var{object}, so that
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
342 each element of @var{array} is @var{object}. It returns @var{array}.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (setq a [a b c d e f g])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 @result{} [a b c d e f g]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (fillarray a 0)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 @result{} [0 0 0 0 0 0 0]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 a
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 @result{} [0 0 0 0 0 0 0]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (setq s "When in the course")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 @result{} "When in the course"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (fillarray s ?-)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 @result{} "------------------"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 If @var{array} is a string and @var{object} is not a character, a
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 @code{wrong-type-argument} error results.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 The general sequence functions @code{copy-sequence} and @code{length}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 are often useful for objects known to be arrays. @xref{Sequence Functions}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 @node Vectors
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 @section Vectors
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 @cindex vector
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 Arrays in Lisp, like arrays in most languages, are blocks of memory
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 whose elements can be accessed in constant time. A @dfn{vector} is a
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
374 general-purpose array; its elements can be any Lisp objects. (By
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
375 contrast, a string can hold only characters as elements.) Vectors in
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
376 Emacs are used for obarrays (vectors of symbols), and as part of keymaps
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
377 (vectors of commands). They are also used internally as part of the
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
378 representation of a byte-compiled function; if you print such a
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
379 function, you will see a vector in it.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 In Emacs Lisp, the indices of the elements of a vector start from zero
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 and count up from there.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
384 Vectors are printed with square brackets surrounding the elements.
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
385 Thus, a vector whose elements are the symbols @code{a}, @code{b} and
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
386 @code{a} is printed as @code{[a b a]}. You can write vectors in the
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
387 same way in Lisp input.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 A vector, like a string or a number, is considered a constant for
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 evaluation: the result of evaluating it is the same vector. This does
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 not evaluate or even examine the elements of the vector.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 @xref{Self-Evaluating Forms}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
394 Here are examples illustrating these principles:
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (setq avector [1 two '(three) "four" [five]])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 @result{} [1 two (quote (three)) "four" [five]]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (eval avector)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 @result{} [1 two (quote (three)) "four" [five]]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (eq avector (eval avector))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
407 @node Vector Functions
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
408 @section Functions That Operate on Vectors
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
409
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 Here are some functions that relate to vectors:
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 @defun vectorp object
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 This function returns @code{t} if @var{object} is a vector.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (vectorp [a])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (vectorp "asdf")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 @result{} nil
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 @defun vector &rest objects
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 This function creates and returns a vector whose elements are the
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 arguments, @var{objects}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (vector 'foo 23 [bar baz] "rats")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 @result{} [foo 23 [bar baz] "rats"]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (vector)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 @result{} []
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 @defun make-vector length object
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 This function returns a new vector consisting of @var{length} elements,
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 each initialized to @var{object}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (setq sleepy (make-vector 9 'Z))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 @result{} [Z Z Z Z Z Z Z Z Z]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 @defun vconcat &rest sequences
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 @cindex copying vectors
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 This function returns a new vector containing all the elements of the
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
454 @var{sequences}. The arguments @var{sequences} may be any kind of
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
455 arrays, including lists, vectors, or strings. If no @var{sequences} are
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
456 given, an empty vector is returned.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 The value is a newly constructed vector that is not @code{eq} to any
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 existing vector.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (setq a (vconcat '(A B C) '(D E F)))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 @result{} [A B C D E F]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (eq a (vconcat a))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 @result{} nil
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (vconcat)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 @result{} []
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (vconcat [A B C] "aa" '(foo (6 7)))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 @result{} [A B C 97 97 foo (6 7)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475
12067
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 7119
diff changeset
476 The @code{vconcat} function also allows integers as arguments. It
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 7119
diff changeset
477 converts them to strings of digits, making up the decimal print
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 7119
diff changeset
478 representation of the integer, and then uses the strings instead of the
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 7119
diff changeset
479 original integers. @strong{Don't use this feature; we plan to eliminate
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 7119
diff changeset
480 it. If you already use this feature, change your programs now!} The
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 7119
diff changeset
481 proper way to convert an integer to a decimal number in this way is with
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 @code{format} (@pxref{Formatting Strings}) or @code{number-to-string}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (@pxref{String Conversion}).
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 For other concatenation functions, see @code{mapconcat} in @ref{Mapping
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 Functions}, @code{concat} in @ref{Creating Strings}, and @code{append}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 in @ref{Building Lists}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 The @code{append} function provides a way to convert a vector into a
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 list with the same elements (@pxref{Building Lists}):
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (setq avector [1 two (quote (three)) "four" [five]])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 @result{} [1 two (quote (three)) "four" [five]]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (append avector nil)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 @result{} (1 two (quote (three)) "four" [five])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 @end example
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
501
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
502 @node Char-Tables
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
503 @section Char-Tables
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
504 @cindex char-tables
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
505
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
506 A char-table is much like a vector, except that it is indexed by
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
507 character codes. Any valid character code, without modifiers, can be
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
508 used as an index in a char-table. You can access a char-table with
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
509 @code{aref} and @code{aset}, just like a vector.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
510
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
511 @cindex extra slots of char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
512 @cindex subtype of char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
513 Each char-table has a @dfn{subtype} which is a symbol. In order to be
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
514 a valid subtype, a symbol must have a @code{char-table-extra-slots}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
515 property which is an integer between 0 and 10. This integer specifies
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
516 the number of @dfn{extra slots} in the char-table.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
517
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
518 @cindex parent of char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
519 A char-table can have a @dfn{parent}. which is another char-table. If
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
520 it does, then whenever the char-table specifies @code{nil} for a
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
521 particular character @var{c}, it inherits the value specified in the
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
522 parent. In other words, @code{(aref @var{char-table} @var{c})} returns
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
523 the value from the parent of @var{char-table} if @var{char-table} itself
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
524 specifies @code{nil}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
525
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
526 @cindex default value of char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
527 A char-table can also have a @dfn{default value}. If so, then
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
528 @code{(aref @var{char-table} @var{c})} returns the default value
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
529 whenever the char-table does not specify any other non-@code{nil} value.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
530
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
531 @tindex make-char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
532 @defun make-char-table subtype &optional init
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
533 Return a newly created char-table, with subtype @var{subtype}. Each
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
534 element is initialized to @var{init}, which defaults to @code{nil}. You
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
535 cannot alter the subtype of a char-table after the char-table is
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
536 created.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
537 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
538
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
539 @tindex char-table-p
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
540 @defun char-table-p object
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
541 This function returns @code{t} if @code{object} is a char-table,
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
542 otherwise @code{nil}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
543 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
544
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
545 @tindex char-table-subtype
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
546 @defun char-table-subtype char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
547 This function returns the subtype symbol of @var{char-table}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
548 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
549
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
550 @tindex set-char-table-default
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
551 @defun set-char-table-default char-table new-default
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
552 This function sets the default value of @var{char-table} to
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
553 @var{new-default}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
554
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
555 There is no special function to access the default value of a char-table.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
556 To do that, use @code{(char-table-range @var{char-table} nil)}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
557 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
558
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
559 @tindex char-table-parent
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
560 @defun char-table-parent char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
561 This function returns the parent of @var{char-table}. The parent is
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
562 always either @code{nil} or another char-table.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
563 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
564
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
565 @tindex set-char-table-parent
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
566 @defun set-char-table-parent char-table new-parent
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
567 This function sets the parent of @var{char-table} to @var{new-parent}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
568 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
569
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
570 @tindex char-table-extra-slot
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
571 @defun char-table-extra-slot char-table n
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
572 This function returns the contents of extra slot @var{n} of
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
573 @var{char-table}. The number of extra slots in a char-table is
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
574 determined by its subtype.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
575 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
576
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
577 @tindex set-char-table-extra-slot
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
578 @defun set-char-table-extra-slot char-table n value
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
579 This function stores @var{value} in extra slot @var{n} of
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
580 @var{char-table}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
581 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
582
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
583 A char-table can specify an element value for a single character code;
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
584 it can also specify a value for an entire character set.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
585
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
586 @tindex char-table-range
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
587 @defun char-table-range char-table range
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
588 This returns the value specified in @var{char-table} for a range of
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
589 characters @var{range}. Here @var{range} may be
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
590
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
591 @table @asis
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
592 @item @code{nil}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
593 Refers to the default value.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
594
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
595 @item @var{char}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
596 Refers to the element for character @var{char}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
597
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
598 @item @var{charset}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
599 Refers to the value specified for the whole character set
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
600 @var{charset} (@pxref{Character Sets}).
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
601 @end table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
602 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
603
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
604 @tindex set-char-table-range
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
605 @defun set-char-table-range char-table range value
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
606 This function set the value in @var{char-table} for a range of
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
607 characters @var{range}. Here @var{range} may be
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
608
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
609 @table @asis
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
610 @item @code{nil}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
611 Refers to the default value.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
612
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
613 @item @code{t}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
614 Refers to the whole range of character codes.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
615
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
616 @item @var{char}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
617 Refers to the element for character @var{char}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
618
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
619 @item @var{charset}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
620 Refers to the value specified for the whole character set
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
621 @var{charset} (@pxref{Character Sets}).
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
622 @end table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
623 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
624
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
625 @tindex map-char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
626 @defun map-char-table function char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
627 This function calls @var{function} for each element of @var{char-table}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
628 @var{function} is called with two arguments, a key and a value. The key
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
629 is a possible @var{range} argument for @code{char-table-range}, and the
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
630 value is @code{(char-table-range @var{char-table} @var{key})}. Invalid
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
631 character codes are never used as the key.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
632
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
633 Overall, the keys-value pairs passed to @var{function} describe all the
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
634 values stored in @var{char-table}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
635 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
636
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
637 @node Bool-Vectors
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
638 @section Bool-vectors
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
639 @cindex Bool-vectors
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
640
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
641 A bool-vector is much like a vector, except that it stores only the
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
642 values @code{t} and @code{nil}. If you try to store any non-@code{nil}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
643 value into an element of the bool-vector, that actually stores @code{t}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
644 there.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
645
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
646 There are two special functions for working with bool-vectors; aside
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
647 from that, you manipulate them with same functions used for other kinds
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
648 of arrays.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
649
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
650 @tindex make-bool-vector
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
651 @defun make-bool-vector length initial
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
652 Return a new book-vector of @var{length} elements,
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
653 each one initialized to @var{initial}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
654 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
655
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
656 @defun bool-vector-p object
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
657 This returns @code{t} if @var{object} is a bool-vector,
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
658 and @code{nil} otherwise.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
659 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
660