sicp-ex-1.39



<< Previous exercise (1.38) | sicp-solutions | Next exercise (1.40) >>


 (define (tan-cf x k) 
   (cont-frac (lambda (i) 
                (if (= i 1) x (- (* x x)))) 
              (lambda (i) 
                (- (* i 2) 1)) 
              k)) 

Another version calculating the square only once using let.

 (define (tan-cf x k) 
   (let ((a (- (* x x)))) 
     (cont-frac (lambda (i) (if (= i 1) x a)) 
              (lambda (i) (- (* i 2) 1)) 
              k)))