From: Ramakrishnan Muthukrishnan Date: Sat, 10 Jul 2010 06:56:41 +0000 (+0530) Subject: solution to 2.27 X-Git-Url: https://git.rkrishnan.org/vdrive/%5B/%5D%20/uri/flags/architecture.txt?a=commitdiff_plain;h=de9c515d5bcef9c012d602464b34a0ef2dac2ae8;p=sicp.git solution to 2.27 --- diff --git a/src/sicp/ex2_27.clj b/src/sicp/ex2_27.clj new file mode 100644 index 0000000..957ec2f --- /dev/null +++ b/src/sicp/ex2_27.clj @@ -0,0 +1,16 @@ +(ns sicp.ex2_27 + (:refer-clojure :exclude (reverse)) + (:use [clojure.test])) + +(def x (list (list 1 2) (list 3 4))) + +(defn deep-reverse [lst] + (cond (not (seq? lst)) lst + (empty? lst) nil + :else (cons (deep-reverse (last lst)) (deep-reverse (butlast lst))))) + +(deftest test-simple-list + (are [x y] [= x y] + (deep-reverse '(1 2 3 4)) '(4 3 2 1) + (deep-reverse '((1 2) 3 4)) '(4 3 (2 1)) + (deep-reverse '((1 2) (3 4))) '((4 3) (2 1))))