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

(info "(elisp) Sequences Arrays Vectors")

Note: “Sequence” and “Array” are not a actual datatype in elisp. They are grouping names for other actual datatypes.

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

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

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.

Vector

Elisp: Vector

List

Elisp: List

Data Structure Topic

  1. Elisp: Sequence: List, Array
  2. Elisp: Vector
  3. Elisp: List
  4. Elisp: Association List
  5. Elisp: Property List
  6. Elisp: Symbol Property List
  7. Elisp: Map / Loop Thru List / Vector
  8. Elisp: Filter a List
  9. Elisp: Hash Table
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.