sicp-ex-3.12



<< Previous exercise (3.11) | Index | Next exercise (3.13) >>


meteorgan

  
  
 z 
 => (a b c d) 
 (cdr x) 
 => (b) 
 w 
 => (a b c d) 
 (cdr x) 
 => (b c d) 
  
  
 z 
 => (a b c d) 
 (cdr x) 
 => (b c d) 
 w 
 => (a b c d) 
 (cdr x) 
 => (b c d) 
  
 (define (append x y) 
   (if (null? x) 
       y 
       (cons (car x) (append (cdr x) y)))) 
  
 (define (append! x y) 
   (define (last-pair x) 
     (if (null? (cdr x)) 
         x 
         (last-pair (cdr x)))) 
   (set-cdr! (last-pair x) y) 
   x) 
  
 (define x (list 'a 'b)) 
 (define y (list 'c 'd)) 
 (define z (append x y)) 
 (define w (append! x y)) 
 ;test it by yourself. 
 ;thank you.