|[ << Scheme tutorial ]||[Top][Contents][Index]||[ Interfaces for programmers >> ]|
|[ < Lists ]||[ Up : Scheme compound data types ]||[ Hash tables > ]|
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
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)) "B" guile>
Alists are widely used in LilyPond to store properties and other data.