]> git.rkrishnan.org Git - sicp.git/commitdiff
rest of section 2.2
authorRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Wed, 25 Aug 2010 18:18:50 +0000 (23:48 +0530)
committerRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Wed, 25 Aug 2010 18:18:50 +0000 (23:48 +0530)
src/sicp/ch2_2.clj

index 93fdcfb7e5bb634c40ff22692856da475d976d50..21e482fff8742894b6d37599d4d18a0c3402745a 100644 (file)
     (flatmap (fn [x]
                (map (fn [p] (cons x p))
                     (permutations (remove x s))))
-             s)))
\ No newline at end of file
+             s)))
+
+
+;;; 2.2.4 picture language
+(defn flipped-pairs [painter]
+  (let [painter2 (beside painter (flipped-vert painter))]
+    (below painter2 painter2)))
+
+(defn right-split [painter n]
+  (if (= n 0)
+    painter
+    (let [smaller (right-split painter (- n 1))]
+      (beside painter (below smaller smaller)))))
+
+(defn corner-split [painter n]
+  (if (= n 0)
+    painter
+    (let [up       (up-split painter (- n 1))
+          right    (right-split painter (- n 1))
+          top-left (beside up up)
+          bottom-right (below right right)
+          corner   (corner-split painter (- n 1))]
+      (beside (below painter top-left)
+              (below bottom-right corner)))))
+
+(defn square-limit [painter n]
+  (let [quarter (corner-split painter n)
+        half    (beside (flip-horiz quarter) quarter)]
+    (below (flip-vert half) half)))