sicp-ex-2.44



<< Previous exercise (2.42) | Index | Next exercise (2.45) >>


jz

I am really uncomfortable writing code that I can't run ... it would be nice if the authors could have come up with an example that didn't assume the presence of other code or libraries. As it is, I'm having a bit of trouble figuring out how this works.

  
 (define (up-split painter n) 
   (cond ((= n 0) painter) 
         (else 
          (let ((smaller (up-split painter (- n 1)))) 
            (below painter (beside smaller smaller)))))) 
  

dudrenov

The gimp comes with a scheme interpreter. Perhaps you can try it there. For me print was good enough.


bxblin

Hello,

If you are using DrRacket, follow these steps:

1) Install the package sicp.plt (Go to file>Install Package, type 'sicp.plt' in package source)

2) Paste this code '(require (planet "sicp.ss" ("soegaard" "sicp.plt" 2 1)))' in your rkt file.

3) Test the file with the code '(paint einstein)'. You should see a picture of Einstein in your command line.

If you want to test your code, do this:

 (require (planet "sicp.ss" ("soegaard" "sicp.plt" 2 1))) 
  
 (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 3)) 
  
 (define (up-split painter n) 
   (if (= n 0) 
       painter 
       (let ((smaller (up-split painter (- n 1)))) 
         (below painter (beside smaller smaller))))) 
  
 (paint (up-split einstein 3))