Next: , Previous: , Up: Sequences Arrays Vectors   [Contents][Index]


12.2 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.

When you create an array, you must specify how many elements it has. The amount of space allocated depends on the number of elements. Therefore, it is impossible to change the size of an array once it is created; you cannot add or remove elements. However, you can replace an element with a different value.

SXEmacs defines three types of array, all of which are one-dimensional: strings, vectors, and bit vectors. A vector is a general array; its elements can be any Lisp objects. A string is a specialized array; its elements must be characters. A bit vector is another specialized array; its elements must be bits (an integer, either 0 or 1). Each type of array has its own read syntax. See String Type, Vector Type, and Bit Vector Type.

All kinds of array share these characteristics:

In principle, if you wish to have 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:

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 non-printable and are represented with symbols rather than with characters. See Key Sequence Input.

Similarly, when representing an array of bits, a bit vector has the following advantages over a regular vector:


Next: , Previous: , Up: Sequences Arrays Vectors   [Contents][Index]