Elisp: List

By Xah Lee. Date: . Last updated: .

What is List

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

Any item can be of any type.

Algorithm properties of lisp list:

Note: List is made up of lower structure called cons cells. 〔see Elisp: Cons Cell

Empty List, nil

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

(eq nil '())
; t

(eq nil (list))
; t

Length

length
(length SEQUENCE)

return count of elements.

(length '(3 4))
;; 2
length=

(length= SEQUENCE N)

return true if length is equal to N.

new in Emacs 28 (date 2022)

💡 TIP: this is more efficient than getting the length then do compare, especially when used on list with lots items. Because to get the length of list, the time is proportional to number of items.

length>

(length> SEQUENCE N)

return true if length is greater than N.

length<

(length< SEQUENCE N)

return true if length is less than N.

Reference

Emacs Lisp, Data Structure

Emacs Lisp, list

Special Lists

List Structure