annotate man/lispref/sequences.texi @ 267:966663fcf606 r20-5b32

Import from CVS: tag r20-5b32
author cvs
date Mon, 13 Aug 2007 10:26:29 +0200
parents 1ce6082ce73f
children 54f7aa390f4f
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
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
305 In this section, we describe the functions that accept strings, vectors,
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
306 and bit vectors.
0
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
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
309 This function returns @code{t} if @var{object} is an array (i.e., a
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
310 string, vector, or bit vector).
0
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
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
314 (arrayp "asdf")
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
315 @result{} t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (arrayp [a])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 @result{} t
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
318 (arrayp #*101)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 @result{} t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 @defun aref array index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 @cindex array elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 This function returns the @var{index}th element of @var{array}. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 first element is at index zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (setq primes [2 3 5 7 11 13])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 @result{} [2 3 5 7 11 13]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (aref 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 (elt primes 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 @result{} 11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (aref "abcdefg" 1)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
341 @result{} ?b
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
342 @end group
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
343
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
344 @group
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
345 (aref #*1101 2)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
346 @result{} 0
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
347 @end group
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 See also the function @code{elt}, in @ref{Sequence Functions}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 @defun aset array index object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 This function sets the @var{index}th element of @var{array} to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 @var{object}. It returns @var{object}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (setq w [foo bar baz])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 @result{} [foo bar baz]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (aset w 0 'fu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 @result{} fu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 @result{} [fu bar baz]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (setq x "asdfasfd")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 @result{} "asdfasfd"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (aset x 3 ?Z)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
371 @result{} ?Z
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 @result{} "asdZasfd"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 @end group
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
375
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
376 @group
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
377 (setq bv #*1111)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
378 @result{} #*1111
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
379 (aset bv 2 0)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
380 @result{} 0
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
381 bv
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
382 @result{} #*1101
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
383 @end group
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 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
387 @code{wrong-type-argument} error results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 @defun fillarray array object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 This function fills the array @var{array} with @var{object}, so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 each element of @var{array} is @var{object}. It returns @var{array}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (setq a [a b c d e f g])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 @result{} [a b c d e f g]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (fillarray a 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 @result{} [0 0 0 0 0 0 0]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 @result{} [0 0 0 0 0 0 0]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 @end group
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
403
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (setq s "When in the course")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 @result{} "When in the course"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (fillarray s ?-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 @result{} "------------------"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 @end group
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
410
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
411 @group
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
412 (setq bv #*1101)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
413 @result{} #*1101
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
414 (fillarray bv 0)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
415 @result{} #*0000
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
416 @end group
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 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
420 @code{wrong-type-argument} error results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 The general sequence functions @code{copy-sequence} and @code{length}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 are often useful for objects known to be arrays. @xref{Sequence Functions}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 @node Vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 @section Vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 @cindex vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 Arrays in Lisp, like arrays in most languages, are blocks of memory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 whose elements can be accessed in constant time. A @dfn{vector} is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 general-purpose array; its elements can be any Lisp objects. (The other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 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
434 characters.) Vectors in XEmacs serve as obarrays (vectors of symbols),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 although this is a shortcoming that should be fixed. They are also used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 internally as part of the representation of a byte-compiled function; if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 you print such a function, you will see a vector in it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 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
440 and count up from there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 Vectors are printed with square brackets surrounding the elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 Thus, a vector whose elements are the symbols @code{a}, @code{b} and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 @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
445 same way in Lisp input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 A vector, like a string or a number, is considered a constant for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 evaluation: the result of evaluating it is the same vector. This does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 not evaluate or even examine the elements of the vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 @xref{Self-Evaluating Forms}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 Here are examples of these principles:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (setq avector [1 two '(three) "four" [five]])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 @result{} [1 two (quote (three)) "four" [five]]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (eval avector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 @result{} [1 two (quote (three)) "four" [five]]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (eq avector (eval avector))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 @result{} t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 @node Vector Functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 @section Functions That Operate on Vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 Here are some functions that relate to vectors:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 @defun vectorp object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 This function returns @code{t} if @var{object} is a vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (vectorp [a])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 @result{} t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (vectorp "asdf")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 @result{} nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 @defun vector &rest objects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 This function creates and returns a vector whose elements are the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 arguments, @var{objects}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (vector 'foo 23 [bar baz] "rats")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 @result{} [foo 23 [bar baz] "rats"]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 @result{} []
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 @defun make-vector length object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 This function returns a new vector consisting of @var{length} elements,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 each initialized to @var{object}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 @example
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 (setq sleepy (make-vector 9 'Z))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 @result{} [Z Z Z Z Z Z Z Z Z]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 @defun vconcat &rest sequences
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 @cindex copying vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 This function returns a new vector containing all the elements of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 @var{sequences}. The arguments @var{sequences} may be lists, vectors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 or strings. If no @var{sequences} are given, an empty vector is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 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
517 existing vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (setq a (vconcat '(A B C) '(D E F)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 @result{} [A B C D E F]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (eq a (vconcat a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 @result{} nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (vconcat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 @result{} []
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (vconcat [A B C] "aa" '(foo (6 7)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 @result{} [A B C 97 97 foo (6 7)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 The @code{vconcat} function also allows integers as arguments. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 converts them to strings of digits, making up the decimal print
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 representation of the integer, and then uses the strings instead of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 original integers. @strong{Don't use this feature; we plan to eliminate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 it. If you already use this feature, change your programs now!} The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 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
540 @code{format} (@pxref{Formatting Strings}) or @code{number-to-string}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (@pxref{String Conversion}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 For other concatenation functions, see @code{mapconcat} in @ref{Mapping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 Functions}, @code{concat} in @ref{Creating Strings}, @code{append}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 in @ref{Building Lists}, and @code{bvconcat} in @ref{Bit Vector Functions}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 The @code{append} function provides a way to convert a vector into a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 list with the same elements (@pxref{Building Lists}):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (setq avector [1 two (quote (three)) "four" [five]])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 @result{} [1 two (quote (three)) "four" [five]]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (append avector nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 @result{} (1 two (quote (three)) "four" [five])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 @node Bit Vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 @section Bit Vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 @cindex bit vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 Bit vectors are specialized vectors that can only represent arrays
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 of 1's and 0's. Bit vectors have a very efficient representation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 and are useful for representing sets of boolean (true or false) values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 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
569 create a bit vector with 100,000 elements if you really wanted to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 Bit vectors have a special printed representation consisting of
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
572 @samp{#*} followed by the bits of the vector. For example, a bit vector
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
573 whose elements are 0, 1, 1, 0, and 1, respectively, is printed as
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 #*01101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 Bit vectors are considered constants for evaluation, like vectors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 strings, and numbers. @xref{Self-Evaluating Forms}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 @node Bit Vector Functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 @section Functions That Operate on Bit Vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 Here are some functions that relate to bit vectors:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 @defun bit-vector-p object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 This function returns @code{t} if @var{object} is a bit vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (bit-vector-p #*01)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 @result{} t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (bit-vector-p [0 1])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 @result{} nil
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
596 (bit-vector-p "01")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 @result{} nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 @defun bitp object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 This function returns @code{t} if @var{object} is either 0 or 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 @defun bit-vector &rest objects
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
607 This function creates and returns a bit vector whose elements are the
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
608 arguments @var{objects}. The elements must be either of the two
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 integers 0 or 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (bit-vector 0 0 0 1 0 0 0 0 1 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 @result{} #*0001000010
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
615 (bit-vector)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 @result{} #*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 @defun make-bit-vector length object
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
622 This function creates and returns a bit vector consisting of
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
623 @var{length} elements, each initialized to @var{object}.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 @group
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
627 (setq picket-fence (make-bit-vector 9 1))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 @result{} #*111111111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 @defun bvconcat &rest sequences
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 @cindex copying bit vectors
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
635 This function returns a new bit vector containing all the elements of
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
636 the @var{sequences}. The arguments @var{sequences} may be lists,
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
637 vectors, or bit vectors, all of whose elements are the integers 0 or 1.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
638 If no @var{sequences} are given, an empty bit vector is returned.
0
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 value is a newly constructed bit vector that is not @code{eq} to any
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
641 existing bit vector.
0
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 a (bvconcat '(1 1 0) '(0 0 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 @result{} #*110001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (eq a (bvconcat a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 @result{} nil
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 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (bvconcat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 @result{} #*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (bvconcat [1 0 0 0 0] #*111 '(0 0 0 0 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 @result{} #*1000011100001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 For other concatenation functions, see @code{mapconcat} in @ref{Mapping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 Functions}, @code{concat} in @ref{Creating Strings}, @code{vconcat} in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 @ref{Vector Functions}, and @code{append} in @ref{Building Lists}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 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
664 list with the same elements (@pxref{Building Lists}):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 @group
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
668 (setq bv #*00001110)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 @result{} #*00001110
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
670 (append bv nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 @result{} (0 0 0 0 1 1 1 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 @end example