Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.

Next: , Previous: , Up: SRFI-1   [Contents][Index]


7.5.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. This extends the core assoc (see Retrieving Alist Entries) by taking an optional = comparison procedure.

The default comparison is equal?. If an = parameter is given it’s called (= key alistcar), i.e. the given target key is the first argument, and a car from alist is second.

For example a case-insensitive string lookup,

(assoc "yy" '(("XX" . 1) ("YY" . 2)) string-ci=?)
⇒ ("YY" . 2)
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), i.e. 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.


Next: , Previous: , Up: SRFI-1   [Contents][Index]