Previous: , Up: Comments   [Index]


D.2.5 Arrays in Elisp

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

Emacs defines four types of array, all one-dimensional:

Vectors and char-tables can hold elements of any type, but strings can only hold characters, and bool-vectors can only hold ‘t’ and ‘nil’.

Shared Characteristics

All four kinds of array share these characteristics:

Text Characters

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:

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.


Previous: Lists in Elisp, Up: Comments   [Index]