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