From: Ramakrishnan Muthukrishnan Date: Sun, 27 Jun 2010 17:04:29 +0000 (+0530) Subject: solution to 2.21 X-Git-Url: https://git.rkrishnan.org/pf/components/com_hotproperty/css/frontends/%3C?a=commitdiff_plain;h=33b355d52ed862757d9565079f662a11a0dca341;p=sicp.git solution to 2.21 --- diff --git a/src/sicp/ex2_21.clj b/src/sicp/ex2_21.clj new file mode 100644 index 0000000..cdabdd8 --- /dev/null +++ b/src/sicp/ex2_21.clj @@ -0,0 +1,18 @@ +(ns sicp.ex2_21 + (:use [clojure test] + [sicp [utils :only (square)]])) + +(defn square-list-1 [items] + (if (empty? items) + nil + (cons (square (first items)) + (square-list-1 (rest items))))) + +(deftest test-square-list-1 + (is (= (square-list-1 (list 1 2 3 4)) (list 1 4 9 16)))) + +(defn square-list-2 [items] + (map (fn [x] (square x)) items)) + +(deftest test-square-list-2 + (is (= (square-list-2 (list 1 2 3 4)) (list 1 4 9 16))))