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)) 

aQuaYi.com

Now is 2019-07-23 09:29:32

Here is Racket-lang code.

  
 #lang sicp 
  
 (#%require sicp-pict) 
  
 (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 4)) 
  

Nico de Vreeze

2019-12-30: Using Racket 7.5. First install sicp using file/package manager and 'sicp'. Having trouble using (load), so using #lang racket and (require)

  
 #lang racket 
 ;; file: par2.2.4.scm 
  
 (provide (all-defined-out)) 
  
 (require sicp-pict) 
  
 ;; (paint einstein) 
  
 ;; use zorro instead of wave 
 (define wave mark-of-zorro) 
  
 (define wave2 (beside wave (flip-vert wave))) 
 (define wave4 (below wave2 wave2)) 
  
 (define (flipped-pairs painter) 
   (let ((painter2 (beside painter (flip-vert painter)))) 
     (below painter2 painter2))) 
  
 ;; cannot redefine procedures 
 (define wave4a (flipped-pairs wave)) 
  
 (define (right-split painter n) 
   (if (= n 0) 
       painter 
       (let ((smaller (right-split painter (- n 1)))) 
         (beside painter (below smaller smaller))))) 
  
 ;; up-split also here. 
 (define (up-split painter n) 
   (if (= n 0) 
       painter 
       (let ((smaller (up-split painter (- n 1)))) 
         (below painter (beside smaller smaller))))) 
  
 (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)) 
               (corner (corner-split painter (- n 1)))) 
           (beside (below painter top-left) 
                   (below bottom-right corner)))))) 
  
 (define (square-limit painter n) 
   (let ((quarter (corner-split painter n))) 
     (let ((half (beside (flip-horiz quarter) quarter))) 
       (below (flip-vert half) half)))) 
  
  
 #lang racket 
 ;; file: ex2.44.scm 
  
 (require sicp-pict) 
  
 (require "par2.2.4.scm") 
  
 (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)) 
 ;; (paint (corner-split einstein 2)) 
  


If you are having trouble getting the picture language to work, I recommend using Dr. Racket and using the following code as an example (https://gist.githubusercontent.com/etscrivner/e0105d9f608b00943a49/raw/683a699aba4984998477adf0c94cd17cdfef0e3e/picture-language.rkt). I am now able to test the code in this section with nicely displayed pictures.

Evan