From 3a27225d827e8719b25ca16c8a8083d7de0f1248 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com> Date: Wed, 25 Aug 2010 23:48:50 +0530 Subject: [PATCH] rest of section 2.2 --- src/sicp/ch2_2.clj | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/sicp/ch2_2.clj b/src/sicp/ch2_2.clj index 93fdcfb..21e482f 100644 --- a/src/sicp/ch2_2.clj +++ b/src/sicp/ch2_2.clj @@ -246,4 +246,32 @@ (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))) -- 2.45.2