SketchyLISP Reference |
Copyright (C) 2007 Nils M Holm |
<<[append] | [Index] | [assp]>> |
Conformance: R5RS Scheme
Purpose:
Retrieve an association from an association list.
An association list is a list of pairs where
the
car
part of each pair holds a key and the
cdr
part of the pair holds the value
associated with that key:
((key1 . value1) ... (keyN . valueN))
Assoc
returns the first association whose key is equal
to a given datum.
Arguments:
X - key of value to be found
A - association list
Implementation:
(define (assoc x a) (cond ((null? a) #f) ((equal? (caar a) x) (car a)) (else (assoc x (cdr a)))))
Example:
(assoc '3 '((1 . i) (2 . ii) (3 . iii) (4 . iv))) => (3 . iii)
<<[append] | [Index] | [assp]>> |