Elisp: Sequence: List, Array
Here's a chart of elisp's most important list-like datatypes.
Note: “Sequence” and “Array” are not actual datatypes in elisp. They are grouping names for other actual datatypes.
When a function's doc says that an argument is a sequence type, it means that it can be list, vector, or string. (e.g.
When a function's doc says an argument is a array type, it means that it can be vector, or string. (e.g.
List and Vector both hold a ordered sequence of values, each value can be any type.
Differences Between List and Vector
Here's the primary differences between list and vector:
- Vector: Access time to any element is constant.
- Vector's length cannot change. (if you create a new copy of a vector, the time required is proportional to the vector's length)
- List: Access time to a element is proportional to the distance of the element's position in the list.
- List's length can grow by prepending element, and can shorten by removing first element. These operations have constant time.
In short, list can grow or shorten, but if you have a long list, say 1 thousand items, accessing 999th item is slow.
Vector has fixed length. Accessing any element is fast.
(info "(elisp) Sequences Arrays Vectors")