1

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?

soegaard
  • 30,661
  • 4
  • 57
  • 106
learn-sicp
  • 69
  • 4

1 Answers1

1

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

Will Ness
  • 70,110
  • 9
  • 98
  • 181
learn-sicp
  • 69
  • 4
  • 2
    If you run into problems using `sicp-pict` with the sicp language, then use `#lang racket` and then `(require sicp-pict)` for that chapter. – soegaard Jun 29 '21 at 21:33