Association lists (alists)

A special type of list is an association list or alist. An alist is used to store data for easy retrieval.

Alists are lists whose elements are pairs. The car of each element is called the key, and the cdr of each element is called the value. The Scheme procedure assoc is used to retrieve an entry from the alist, and cdr is used to retrieve the value:

guile> (define my-alist '((1  . "A") (2 . "B") (3 . "C")))
guile> my-alist
((1 . "A") (2 . "B") (3 . "C"))
guile> (assoc 2 my-alist)
(2 . "B")
guile> (cdr (assoc 2 my-alist))

Alists are widely used in LilyPond to store properties and other data.

Extending LilyPond v2.25.10 (development-branch).