annotate man/lispref/sequences.texi @ 0:376386a54a3c r19-14

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