Next: , Previous: SRFI-1 Deleting, Up: SRFI-1


6.4.3.9 Association Lists

Association lists are described in detail in section Association Lists. The present section only documents the additional procedures for dealing with association lists defined by SRFI-1.

— Scheme Procedure: assoc key alist [=]

Return the pair from alist which matches key. Equality is determined by =, which defaults to equal? if not given. alist must be an association lists—a list of pairs.

This function extends the core assoc by accepting an equality predicate. (see Association Lists)

— Scheme Procedure: alist-cons key datum alist

Cons a new association key and datum onto alist and return the result. This is equivalent to

          (cons (cons key datum) alist)
     

acons (see Adding or Setting Alist Entries) in the Guile core does the same thing.

— Scheme Procedure: alist-copy alist

Return a newly allocated copy of alist, that means that the spine of the list as well as the pairs are copied.

— Scheme Procedure: alist-delete key alist [=]
— Scheme Procedure: alist-delete! key alist [=]

Return a list containing the elements of alist but with those elements whose keys are equal to key deleted. The returned elements will be in the same order as they were in alist.

Equality is determined by the = predicate, or equal? if not given. The order in which elements are tested is unspecified, but each equality call is made (= key alistkey), ie. the given key parameter is first and the key from alist second. This means for instance all associations with a key greater than 5 can be removed with (alist-delete 5 alist <).

alist-delete does not modify alist, but the return might share a common tail with alist. alist-delete! may modify the list structure of alist to construct its return.