assoc

Name

assoc -- Returns the association of an object in an associative list

Synopsis

(assoc obj alist)

Description

Given an associative list, returns the pair that has obj as a car or #f if no such pair exists.

obj

The associative key to locate.

alist

The associative list.

Example

(assoc "a" (("a" "b") ("c" "d"))) returns ("a" "b")

Author

Norman Walsh, <ndw@nwalsh.com>

Source Code

(define (assoc obj alist)
  ;; Returns the association of an object in an associative list
  (let loop ((al alist))
    (if (null? al)
	#f
	(if (equal? obj (car (car al)))
	    (car al)
	    (loop (cdr al))))))