Expression | Value | (define computer-prefs
'((peter . windows) (lars . mac)
(paw . linux) (kurt . unix))) | | (assq 'lars computer-prefs) | (lars . mac) | (assq 'kurt computer-prefs) | (kurt . unix) | (define computer-prefs-1
(cons (cons 'lene 'windows)
computer-prefs)) | | computer-prefs-1 | ((lene . windows)
(peter . windows)
(lars . mac)
(paw . linux)
(kurt . unix)) |
| | Examples of association lists. The function assq uses eq? to compare the first parameter
with the first element - the key element - in the pairs. As an alternative, we could use
the function assoc, which uses equal? for comparison. A better and more general solution would be
to pass the comparison function as parameter. Notice in this context, that both assq and assoc are 'traditional Lisp functions' and part of Scheme, as defined in the language report. |