Arrays
======
An "array" object has slots that hold a number of other Lisp
objects, called the elements of the array. Any element of an array may
be accessed in constant time. In contrast, an element of a list
requires access time that is proportional to the position of the element
in the list.
Emacs defines four types of array, all one-dimensional: "strings",
"vectors", "bool-vectors" and "char-tables". A vector is a general
array; its elements can be any Lisp objects. A string is a specialized
array; its elements must be characters. Each type of array has its own
read syntax. Note:String Type, and Note:Vector Type.
All four kinds of array share these characteristics:
* The first element of an array has index zero, the second element
has index 1, and so on. This is called "zero-origin" indexing.
For example, an array of four elements has indices 0, 1, 2, and 3.
* The length of the array is fixed once you create it; you cannot
change the length of an existing array.
* The array is a constant, for evaluation--in other words, it
evaluates to itself.
* The elements of an array may be referenced or changed with the
functions `aref' and `aset', respectively (Note:Array
Functions).
When you create an array, other than a char-table, you must specify
its length. You cannot specify the length of a char-table, because that
is determined by the range of character codes.
In principle, if you want an array of text characters, you could use
either a string or a vector. In practice, we always choose strings for
such applications, for four reasons:
* They occupy one-fourth the space of a vector of the same elements.
* Strings are printed in a way that shows the contents more clearly
as text.
* Strings can hold text properties. Note:Text Properties.
* Many of the specialized editing and I/O facilities of Emacs accept
only strings. For example, you cannot insert a vector of
characters into a buffer the way you can insert a string. Note:Strings and Characters.
By contrast, for an array of keyboard input characters (such as a key
sequence), a vector may be necessary, because many keyboard input
characters are outside the range that will fit in a string. Note:Key
Sequence Input.