1
votes

The "Painter" example from SICP 2.2.4 is pretty interesting, and gives ways to create nice Escher-like paintings. For example, a recursive right-split procedure can be done something like:

(define (right-split painter n)
  (if (= n 0)
      painter
      (let ((smaller (right-split painter (- n 1))))
         (beside painter (below smaller smaller)))))

However, none of these examples can actually be run or visualized. Is there any sort of "input painter" that can be used (even ASCI text/art, like a circle or square) to illustrate how the procedures can actually be used in a complete manner?

1

1 Answers

2
votes

Racket can help with this:

#lang sicp

(#%require sicp-pict)

(define (right-split painter n)
  (if (= n 0)
      painter
      (let ((smaller (right-split painter (- n 1))))
         (beside painter (below smaller smaller)))))

(paint (right-split einstein 2))

enter image description here