Implementation of assoc


; Associate item x with list of pairs alist
(define (assoc1 x alist)
  (if (pair? alist)
      (if (and (pair? (car alist))
               (equal? x (caar alist)))
          (car alist)
          (assoc1 x (cdr alist)))
      #f) )

> (define *cardinals* '((one 1) (two 2) (three 3))) *cardinals*

> (assoc1 'two *cardinals*) (two 2)

> (cadr (assoc1 'two *cardinals*)) 2

Contents    Page-10    Prev    Next    Page+10    Index