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