Emacs Lisp: List

By Xah Lee. Date: . Last updated: .

Emacs Lisp's list datatype is an ordered sequence of things. It is known as linked list data structure in computer science. It is an efficient datatype for stack data structure. (like a stack of books, allowing adding or removing one item at a time from the top in an efficient way.)

Lisp list are made up of lower structure called cons, as nested Cons Pair.

Any item can be of any type.

Algorithm properties of lisp list:

Create List

Empty List, nil

In elisp, empty list is equivalent to nil. The following are all equivalent.

(eq '() (list ) ) ; t
(eq '() nil); t
(eq (list ) nil ) ; t

Length

length
(length SEQUENCE)

return count of elements.

(equal (length '("a" "b" "c") ) 3)

Get Element from List

Add to List

cons
(cons new list)

Return a new list, with new added to front. (prepend)

(equal
 (cons "a" '("c" "d"))
 '("a" "c" "d"))

(equal
 (cons '("a" "b") '("c" "d"))
 '(("a" "b") "c" "d"))

see also • add-to-listadd-to-ordered-listpush at Emacs Lisp: Modify List

Modify List Variable

Append Join, Convert List

Reference

Lisp Data Structure

List

Vector

Sequence (List, Vector)

Hash Table