annotate lispref/sequences.texi @ 54773:a4825fc03ab1

(WinMain): Let emacs environment default to parent.
author Jason Rumney <jasonr@gnu.org>
date Sat, 10 Apr 2004 21:05:50 +0000
parents 3839917a7e9e
children dc1950724cd9
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.
27189
d2e5f1b7d8e2 Update copyrights.
Gerd Moellmann <gerd@gnu.org>
parents: 27187
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38941
diff changeset
4 @c Free Software Foundation, Inc.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 @c See the file elisp.texi for copying conditions.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 @chapter Sequences, Arrays, and Vectors
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 @cindex sequence
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
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
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
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
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
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 The elements of vectors and lists may be any Lisp objects. The
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 elements of strings are all characters.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 @menu
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 * Sequence Functions:: Functions that accept any kind of sequence.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 * Arrays:: Characteristics of arrays in Emacs Lisp.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 * Array Functions:: Functions specifically for arrays.
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
57 * Vectors:: Special characteristics of Emacs Lisp vectors.
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
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
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 @end menu
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 @node Sequence Functions
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 @section Sequences
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 @defun sequencep object
52787
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
72 Returns @code{t} if @var{object} is a list, vector,
52843
e05aaf8021c8 (Sequence Functions): sequencep accepts bool-vectors.
Richard M. Stallman <rms@gnu.org>
parents: 52787
diff changeset
73 string, bool-vector, or char-table, @code{nil} otherwise.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
52787
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
81 @cindex char-table length
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
82 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
83 @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
84 @sc{cdr} is not @code{nil}), a @code{wrong-type-argument} error is
52787
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
85 signaled. For a char-table, the value returned is always one more
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
86 than the maximum Emacs character code.
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
87
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
88 @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
89
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
90 @example
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
91 @group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
92 (length '(1 2 3))
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
93 @result{} 3
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
94 @end group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
95 @group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
96 (length ())
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
97 @result{} 0
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
98 @end group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
99 @group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
100 (length "foobar")
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
101 @result{} 6
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
102 @end group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
103 @group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
104 (length [1 2 3])
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
105 @result{} 3
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
106 @end group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
107 @group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
108 (length (make-bool-vector 5 nil))
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
109 @result{} 5
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
110 @end group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
111 @end example
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
112 @end defun
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
113
52787
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
114 @defun string-bytes string
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
115 @cindex string, number of bytes
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
116 This function returns the number of bytes in @var{string}.
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
117 If @var{string} is a multibyte string, this is greater than
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
118 @code{(length @var{string})}.
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
119 @end defun
785941182067 Char-tables are sequences.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
120
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
121 @defun elt sequence index
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
122 @cindex elements of sequences
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
123 This function returns the element of @var{sequence} indexed by
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
124 @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
125 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
126 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
127 otherwise, they trigger an @code{args-out-of-range} error.
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
128
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
129 @example
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
130 @group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
131 (elt [1 2 3 4] 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) 2)
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
136 @result{} 3
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 ;; @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
140 (string (elt "1234" 2))
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
141 @result{} "3"
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
142 @end group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
143 @group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
144 (elt [1 2 3 4] 4)
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
145 @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
146 @end group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
147 @group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
148 (elt [1 2 3 4] -1)
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
149 @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
150 @end group
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
151 @end example
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
152
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
153 This function generalizes @code{aref} (@pxref{Array Functions}) and
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
154 @code{nth} (@pxref{List Elements}).
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
155 @end defun
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
156
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 @defun copy-sequence sequence
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 @cindex copying sequences
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 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
160 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
161
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 Storing a new element into the copy does not affect the original
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 @var{sequence}, and vice versa. However, the elements of the new
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 sequence are not copies; they are identical (@code{eq}) to the elements
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 of the original. Therefore, changes made within these elements, as
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 found via the copied sequence, are also visible in the original
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 sequence.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 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
170 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
171 list. However, the actual values of the properties are shared.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 @xref{Text Properties}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 See also @code{append} in @ref{Building Lists}, @code{concat} in
54479
3839917a7e9e (Sequence Functions): Replace xref to `Vectors' with `Vector Functions'.
Juri Linkov <juri@jurta.org>
parents: 52978
diff changeset
175 @ref{Creating Strings}, and @code{vconcat} in @ref{Vector Functions},
3839917a7e9e (Sequence Functions): Replace xref to `Vectors' with `Vector Functions'.
Juri Linkov <juri@jurta.org>
parents: 52978
diff changeset
176 for other ways to copy sequences.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (setq bar '(1 2))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 @result{} (1 2)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (setq x (vector 'foo bar))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 @result{} [foo (1 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (setq y (copy-sequence x))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 @result{} [foo (1 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191
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 (eq x y)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 @result{} nil
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 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (equal x y)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (eq (elt x 1) (elt y 1))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; @r{Replacing an element of one sequence.}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (aset x 0 'quux)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 x @result{} [quux (1 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 y @result{} [foo (1 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 @end group
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 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 ;; @r{Modifying the inside of a shared element.}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (setcar (aref x 1) 69)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 x @result{} [quux (69 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 y @result{} [foo (69 2)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 @node Arrays
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 @section Arrays
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 @cindex array
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 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
226 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
227 be accessed in constant time. In contrast, an element of a list
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 requires access time that is proportional to the position of the element
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 in the list.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
231 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
232 @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
233 general array; its elements can be any Lisp objects. A string is a
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38941
diff changeset
234 specialized array; its elements must be characters. Each type of array
26254
a393c5e46e99 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26239
diff changeset
235 has its own read syntax.
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
236 @xref{String Type}, and @ref{Vector Type}.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
238 All four kinds of array share these characteristics:
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 @itemize @bullet
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 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
243 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
244 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
245
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 @item
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
247 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
248 change the length of an existing array.
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
249
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
250 @item
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
251 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
252 to itself.
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 @item
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 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
256 @code{aref} and @code{aset}, respectively (@pxref{Array Functions}).
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
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
259 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
260 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
261 is determined by the range of character codes.
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
262
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
263 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
264 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
265 such applications, for four reasons:
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 @itemize @bullet
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 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
270
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 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
273 as text.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 Strings can hold text properties. @xref{Text Properties}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 @item
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 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
280 strings. For example, you cannot insert a vector of characters into a
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 buffer the way you can insert a string. @xref{Strings and Characters}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 @end itemize
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
284 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
285 sequence), a vector may be necessary, because many keyboard input
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
286 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
287 Sequence Input}.
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
288
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 @node Array Functions
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 @section Functions that Operate on Arrays
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
292 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
293 arrays.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 @defun arrayp object
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
296 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
297 vector, a string, a bool-vector or a char-table).
6374
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 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (arrayp [a])
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
302 @result{} t
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (arrayp "asdf")
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
304 @result{} t
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
305 (arrayp (syntax-table)) ;; @r{A char-table.}
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
306 @result{} t
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 @defun aref array index
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 @cindex array elements
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 This function returns the @var{index}th element of @var{array}. The
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 first element is at index zero.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (setq primes [2 3 5 7 11 13])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 @result{} [2 3 5 7 11 13]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (aref primes 4)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 @result{} 11
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (aref "abcdefg" 1)
52978
1a5c50faf357 Replace @sc{foo} with @acronym{FOO}.
Eli Zaretskii <eliz@gnu.org>
parents: 52843
diff changeset
325 @result{} 98 ; @r{@samp{b} is @acronym{ASCII} code 98.}
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 See also the function @code{elt}, in @ref{Sequence Functions}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 @end defun
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 @defun aset array index object
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 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
334 @var{object}. It returns @var{object}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (setq w [foo bar baz])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 @result{} [foo bar baz]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (aset w 0 'fu)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 @result{} fu
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 w
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 @result{} [fu bar baz]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (setq x "asdfasfd")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 @result{} "asdfasfd"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (aset x 3 ?Z)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 @result{} 90
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 x
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 @result{} "asdZasfd"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 If @var{array} is a string and @var{object} is not a character, a
30983
ce8c496b524d aset change.
Dave Love <fx@gnu.org>
parents: 27189
diff changeset
357 @code{wrong-type-argument} error results. The function converts a
ce8c496b524d aset change.
Dave Love <fx@gnu.org>
parents: 27189
diff changeset
358 unibyte string to multibyte if necessary to insert a character.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 @end defun
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 @defun fillarray array object
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
362 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
363 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
364
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (setq a [a b c d e f g])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 @result{} [a b c d e f g]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (fillarray a 0)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 @result{} [0 0 0 0 0 0 0]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 a
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 @result{} [0 0 0 0 0 0 0]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (setq s "When in the course")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 @result{} "When in the course"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (fillarray s ?-)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 @result{} "------------------"
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 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
383 @code{wrong-type-argument} error results.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 The general sequence functions @code{copy-sequence} and @code{length}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 are often useful for objects known to be arrays. @xref{Sequence Functions}.
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 @node Vectors
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 @section Vectors
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 @cindex vector
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 Arrays in Lisp, like arrays in most languages, are blocks of memory
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 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
395 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
396 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
397 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
398 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
399 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
400 function, you will see a vector in it.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 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
403 and count up from there.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
405 Vectors are printed with square brackets surrounding the elements.
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
406 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
407 @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
408 same way in Lisp input.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 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
411 evaluation: the result of evaluating it is the same vector. This does
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 not evaluate or even examine the elements of the vector.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 @xref{Self-Evaluating Forms}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
415 Here are examples illustrating these principles:
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (setq avector [1 two '(three) "four" [five]])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 @result{} [1 two (quote (three)) "four" [five]]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (eval avector)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 @result{} [1 two (quote (three)) "four" [five]]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (eq avector (eval avector))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
428 @node Vector Functions
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
429 @section Functions for Vectors
7119
19bd3bfc57de entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6374
diff changeset
430
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 Here are some functions that relate to vectors:
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 @defun vectorp object
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 This function returns @code{t} if @var{object} is a vector.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (vectorp [a])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 @result{} t
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (vectorp "asdf")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 @result{} nil
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 @defun vector &rest objects
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 This function creates and returns a vector whose elements are the
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 arguments, @var{objects}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (vector 'foo 23 [bar baz] "rats")
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 @result{} [foo 23 [bar baz] "rats"]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (vector)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 @result{} []
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 @defun make-vector length object
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 This function returns a new vector consisting of @var{length} elements,
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 each initialized to @var{object}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (setq sleepy (make-vector 9 'Z))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 @result{} [Z Z Z Z Z Z Z Z Z]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 @defun vconcat &rest sequences
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 @cindex copying vectors
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 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
475 @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
476 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
477 given, an empty vector is returned.
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 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
480 existing vector.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (setq a (vconcat '(A B C) '(D E F)))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 @result{} [A B C D E F]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (eq a (vconcat a))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 @result{} nil
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (vconcat)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 @result{} []
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (vconcat [A B C] "aa" '(foo (6 7)))
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 @result{} [A B C 97 97 foo (6 7)]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 @end example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
497 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
498 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
499 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
500
52147
b111b96616f0 (Vector Functions): vconcat no longer allows integer args.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
501 In Emacs versions before 21, the @code{vconcat} function allowed
b111b96616f0 (Vector Functions): vconcat no longer allows integer args.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
502 integers as arguments, converting them to strings of digits, but that
b111b96616f0 (Vector Functions): vconcat no longer allows integer args.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
503 feature has been eliminated. The proper way to convert an integer to
b111b96616f0 (Vector Functions): vconcat no longer allows integer args.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
504 a decimal number in this way is with @code{format} (@pxref{Formatting
b111b96616f0 (Vector Functions): vconcat no longer allows integer args.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
505 Strings}) or @code{number-to-string} (@pxref{String Conversion}).
6374
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 For other concatenation functions, see @code{mapconcat} in @ref{Mapping
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 Functions}, @code{concat} in @ref{Creating Strings}, and @code{append}
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 in @ref{Building Lists}.
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 @end defun
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 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
513 list with the same elements (@pxref{Building Lists}):
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 @example
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 @group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (setq avector [1 two (quote (three)) "four" [five]])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 @result{} [1 two (quote (three)) "four" [five]]
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (append avector nil)
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 @result{} (1 two (quote (three)) "four" [five])
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 @end group
71e61b314fe9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 @end example
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
523
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
524 @node Char-Tables
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
525 @section Char-Tables
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
526 @cindex char-tables
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
527 @cindex extra slots of char-table
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
528
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
529 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
530 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
531 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
532 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
533 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
534 data not associated with particular character codes. Char-tables are
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
535 constants when evaluated.
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
536
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
537 @cindex subtype of char-table
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
538 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
539 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
540 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
541 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
542 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
543 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
544 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
545 @dfn{extra slots} in the char-table.
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
546
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
547 @cindex parent of char-table
38941
bf397d008909 Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 38789
diff changeset
548 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
549 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
550 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
551 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
552 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
553 specifies @code{nil}.
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 @cindex default value of char-table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
556 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
557 @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
558 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
559
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
560 @defun make-char-table subtype &optional init
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
561 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
562 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
563 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
564 created.
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
565
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
566 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
567 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
568 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
569
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
570 @defun char-table-p object
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
571 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
572 otherwise @code{nil}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
573 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
574
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
575 @defun char-table-subtype char-table
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
576 This function returns the subtype symbol of @var{char-table}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
577 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
578
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
579 @defun set-char-table-default char-table new-default
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
580 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
581 @var{new-default}.
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 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
584 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
585 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
586
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
587 @defun char-table-parent char-table
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
588 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
589 always either @code{nil} or another char-table.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
590 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
591
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
592 @defun set-char-table-parent char-table new-parent
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
593 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
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 char-table-extra-slot char-table n
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
597 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
598 @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
599 determined by its subtype.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
600 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
601
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
602 @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
603 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
604 @var{char-table}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
605 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
606
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
607 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
608 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
609
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
610 @defun char-table-range char-table range
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
611 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
612 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
613
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
614 @table @asis
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
615 @item @code{nil}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
616 Refers to the default value.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
617
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
618 @item @var{char}
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
619 Refers to the element for character @var{char}
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
620 (supposing @var{char} is a valid character code).
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
621
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
622 @item @var{charset}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
623 Refers to the value specified for the whole character set
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
624 @var{charset} (@pxref{Character Sets}).
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
625
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
626 @item @var{generic-char}
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
627 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
628 character as argument is equivalent to specifying the character set
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
629 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
630 @end table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
631 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
632
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
633 @defun set-char-table-range char-table range value
22252
40089afa2b1d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 22138
diff changeset
634 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
635 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
636
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
637 @table @asis
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
638 @item @code{nil}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
639 Refers to the default value.
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 @item @code{t}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
642 Refers to the whole range of character codes.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
643
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
644 @item @var{char}
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
645 Refers to the element for character @var{char}
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
646 (supposing @var{char} is a valid character code).
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
647
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
648 @item @var{charset}
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
649 Refers to the value specified for the whole character set
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
650 @var{charset} (@pxref{Character Sets}).
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
651
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
652 @item @var{generic-char}
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
653 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
654 character as argument is equivalent to specifying the character set
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
655 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
656 @end table
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
657 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
658
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
659 @defun map-char-table function char-table
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
660 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
661 @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
662 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
663 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
664 @code{(char-table-range @var{char-table} @var{key})}.
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
665
21682
90da2489c498 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21007
diff changeset
666 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
667 values stored in @var{char-table}.
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
668
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
669 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
670 @var{function} should have side effects. For example,
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
671 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
672
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
673 @example
22252
40089afa2b1d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 22138
diff changeset
674 (let (accumulator)
40089afa2b1d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 22138
diff changeset
675 (map-char-table
40089afa2b1d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 22138
diff changeset
676 #'(lambda (key value)
40089afa2b1d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 22138
diff changeset
677 (setq accumulator
40089afa2b1d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 22138
diff changeset
678 (cons (list key value) accumulator)))
40089afa2b1d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 22138
diff changeset
679 (syntax-table))
40089afa2b1d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 22138
diff changeset
680 accumulator)
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
681 @result{}
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
682 ((475008 nil) (474880 nil) (474752 nil) (474624 nil)
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
683 ... (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
684 @end example
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
685 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
686
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
687 @node Bool-Vectors
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
688 @section Bool-vectors
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
689 @cindex Bool-vectors
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
690
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
691 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
692 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
693 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
694 @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
695 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
696 Bool-vectors are constants when evaluated.
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
697
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
698 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
699 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
700 of arrays.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
701
22138
d4ac295a98b3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 21682
diff changeset
702 @defun make-bool-vector length initial
38019
59051c56859f Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 30983
diff changeset
703 Return a new bool-vector of @var{length} elements,
21007
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
704 each one initialized to @var{initial}.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
705 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
706
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
707 @defun bool-vector-p object
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
708 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
709 and @code{nil} otherwise.
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
710 @end defun
66d807bdc5b4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12098
diff changeset
711
38789
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
712 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
713 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
714 values as a single character.
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
715
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
716 @example
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
717 (setq bv (make-bool-vector 5 t))
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
718 @result{} #&5"^_"
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
719 (aref bv 1)
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
720 @result{} t
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
721 (aset bv 3 nil)
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
722 @result{} nil
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
723 bv
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
724 @result{} #&5"^W"
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
725 @end example
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
726
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
727 @noindent
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
728 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
729 control-W are 11111 and 10111, respectively.
72006230a5d8 Add bool-vector example.
Richard M. Stallman <rms@gnu.org>
parents: 38019
diff changeset
730
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52147
diff changeset
731 @ignore
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52147
diff changeset
732 arch-tag: fcf1084a-cd29-4adc-9f16-68586935b386
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52147
diff changeset
733 @end ignore