t3x.org / sketchy / library / assv.html
SketchyLISP
Reference
  Copyright (C) 2007
Nils M Holm

assv

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))
Assv returns the first association whose key is equivalent to a given atom.

Arguments:
X - key of value to be found
A - association list

Implementation:

(define (assv x a)
  (cond ((null? a) #f)
    ((eqv? (caar a) x) (car a))
    (else (assv x (cdr a)))))

Example:

(assv '2 '((1 . i) (2 . ii) (3 . iii) (4 . iv))) 
=> (2 . ii)

See also:
assoc, assq, memv.