annotate man/lispref/sequences.texi @ 5791:9fae6227ede5

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