From: Ramakrishnan Muthukrishnan Date: Sun, 12 Sep 2010 18:11:08 +0000 (+0530) Subject: adding the key lookup procedure X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/frontends/?a=commitdiff_plain;h=d3f263959cba4c54a4e785ee0e34bc520d7d37c0;p=sicp.git adding the key lookup procedure --- diff --git a/src/sicp/ch2_3.clj b/src/sicp/ch2_3.clj index a69973c..55ef8ad 100644 --- a/src/sicp/ch2_3.clj +++ b/src/sicp/ch2_3.clj @@ -136,3 +136,9 @@ (left-branch set) (adjoin-set x (right-branch set))))) + +;;; key lookup +(defn lookup [given-key set-of-records] + (cond (empty? set-of-records) false + (equal? given-key (key (first set-of-records))) (first set-of-records) + :else (lookup given-key (rest set-of-records)))) \ No newline at end of file