| www.delorie.com/gnu/docs/guile/guile_246.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
assq, assv and assoc take an alist and a key as
arguments and return the entry for that key if an entry exists, or
#f if there is no entry for that key. Note that, in the cases
where an entry exists, these procedures return the complete entry, that
is (KEY . VALUE), not just the value.
assq compares keys with eq?, assv
uses eqv? and assoc uses equal?. If key
cannot be found in alist (according to whichever equality
predicate is in use), then return #f. These functions
return the entire alist entry found (i.e. both the key and the value).
assq-ref, assv-ref and assoc-ref, on the other
hand, take an alist and a key and return just the value for that
key, if an entry exists. If there is no entry for the specified key,
these procedures return #f.
This creates an ambiguity: if the return value is #f, it means
either that there is no entry with the specified key, or that there
is an entry for the specified key, with value #f.
Consequently, assq-ref and friends should only be used where it
is known that an entry exists, or where the ambiguity doesn't matter
for some other reason.
assq, assv and assoc, except that only the
value associated with key in alist is returned. These
functions are equivalent to
(let ((ent (associator key alist))) (and ent (cdr ent))) |
where associator is one of assq, assv or assoc.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |