sicp-ex-3.58



<< Previous exercise (3.57) | Index | Next exercise (3.59) >>


meteorgan



The result is the rational value that num divide den in base radix.
(expand 1 7 10)
=> 1 4 2 8 5 7 4 2 8 5 7 ...
(expand 3 8 10)
=> 3 7 5 0 0 0 ...

I think @meteorgan miscalculate (expand 1 7 10). => 1 4 2 8 5 7 1 4 2 8 5 7 ...



xdavidliu

The result is the floating-point representation of (/ num den) with radix as the base.

 ;; list of first n elements of stream 
 (define (partial-stream->list stream n) 
   (define (rec str i) 
     (if (= i n) 
         () 
         (cons (stream-car str) 
               (rec (stream-cdr str) (1+ i))))) 
   (rec stream 0)) 
  
 (partial-stream->list (expand 1 7 10) 10) 
 ;Value: (1 4 2 8 5 7 1 4 2 8) 
  
 (/ 1.0 7) 
 ;Value: .14285714285714285 
  
 (partial-stream->list (expand 3 8 10) 5) 
 ;Value: (3 7 5 0 0) 
  
 (/ 3.0 8) 
 ;Value: .375