sicp-ex-2.45



<< Previous exercise (2.44) | Index | Next exercise (2.46) >>


jz

  
 (define (split orig-placer split-placer) 
   (lambda (painter n) 
     (cond ((= n 0) painter) 
           (else 
            (let ((smaller ((split orig-placer split-placer) painter (- n 1)))) 
              (orig-placer painter (split-placer smaller smaller))))))) 
  


brave brother

i think explicit internal func makes it clearer. but the same sure.

  
 (define (split f g) 
   (define (rec painter n) 
     (if (= n 1) 
         painter 
         (let ((smaller (rec painter (- n 1)))) 
           (f painter (g smaller smaller))))) 
   rec) 
  

woofy

Also including left-split and down split?

  
 (define (split main sub flip) 
     (define (do painter n) 
         (if (= n 0) 
             painter 
             (let ((smaller (do painter (- n 1)))) 
                 (flip (main painter (sub smaller smaller)))))) 
     do) 
  
 (define right-split (split beside below identity)) 
 (define up-split (split below beside identity)) 
 (define left-split (split beside below flip-horiz)) 
 (define down-split (split below beside flip-vert)) 
  
 ; or this is better already 
 (define left-split (compose flip-horiz right-split)) 
 (define down-split (compose flip-vert down-split))