From a0fa6d5035f52ed146bbe2a81da9d6e040be47d6 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Thu, 2 Sep 2010 01:24:06 +0530 Subject: [PATCH] solution to 2.54 --- src/sicp/ex2_54.clj | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/sicp/ex2_54.clj diff --git a/src/sicp/ex2_54.clj b/src/sicp/ex2_54.clj new file mode 100644 index 0000000..0039c29 --- /dev/null +++ b/src/sicp/ex2_54.clj @@ -0,0 +1,27 @@ +(ns sicp.ex2_54 + (:use [clojure.test])) + +(defn atom? [x] + (not (list? x))) + +(defn eq? [x y] + (if (not (atom? x)) + false + (= x y))) + +(defn equal? [a b] + (cond (empty? a) (empty? b) + (atom? (first a)) + (if (eq? (first a) (first b)) + (equal? (rest a) (rest b)) + false) + :else (and (equal? (first a) (first b)) + (equal? (rest a) (rest b))))) + +(deftest test-equality + (are [x y] [= x y] + (equal? '(1) '(1)) true + (equal? '(1) '(2)) false + (equal? '(1 2) '(1 2)) true + (equal? '(1 2 (3)) '(1 2 (3))) true + (equal? '(1 2 3) '(1 2 (3))) false)) \ No newline at end of file -- 2.45.2