Elisp: Sequence: List, Array

By Xah Lee. Date: . Last updated: .

Here's a chart of elisp's most important list-like datatypes.

emas lisp data structure
Most commonly used list-like data structure in elisp. (note: there's also char-table and bool-vector datatypes, which are sub-types of of array type. They are more specialized.)

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

When a function's doc says an argument is a array type, it means that it can be vector, or string. (e.g. aref)

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:

  1. Vector: Access time to any element is constant.
  2. Vector's length cannot change. (if you create a new copy of a vector, the time required is proportional to the vector's length)
  1. List: Access time to a element is proportional to the distance of the element's position in the list.
  2. 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")

Elisp Data Structure

  1. List
  2. Vector
  3. Sequence: List, Array
  4. Sequence Functions
  5. Map List/Vector
  6. Exit Loop/Function
  7. Association List
  8. Property List
  9. Symbol Property List
  10. Hash Table

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp