-
Notifications
You must be signed in to change notification settings - Fork 5
/
2.44.scm
executable file
·36 lines (29 loc) · 1.08 KB
/
2.44.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#lang racket
(require (planet "sicp.ss" ("soegaard" "sicp.plt" 2 1)))
;Picture language extension
;See http://planet.plt-scheme.org/package-source/soegaard/sicp.plt/2/1/planet-docs/sicp-manual/index.html
;Make sure enable 'Determine Language from source'
;See http://www.billthelizard.com/2011/08/sicp-244-245-picture-language.html for a good guide
;Setup
(define (right-split painter n)
(if (= n 0)
painter
(let ((smaller (right-split painter (- n 1))))
(beside painter (below smaller smaller)))))
;Ex 2.44
(define (up-split painter n)
(if (= n 0)
painter
(let ((smaller (up-split painter (- n 1))))
(below painter (beside smaller smaller) ))))
;Test
(define (corner-split painter n)
(if (= n 0)
painter
(let ((up (up-split painter (- n 1 )))
(right (right-split painter (- n 1))))
(let ((top-left (beside up up))
(bottom-right (below right right)))
(below (beside painter bottom-right)
(beside top-left (corner-split painter (- n 1))))))))
(paint (corner-split einstein 4 ))