Auxiliary Function for Recursion

Sometimes it is useful to define an auxiliary function in order to introduce extra variables during the recursion.


(define (mysqrt x) (mysqrtb x 1.0 4))

(define (mysqrtb x estimate n) (if (<= n 0) estimate (mysqrtb x (new-estimate x estimate) (1- n)) ) )

(define (1- n) (- n 1))

(define (new-estimate x estimate) (/ (+ estimate (/ x estimate)) 2))

In this case, we want the function mysqrt to have only a single parameter x, while the recursive function needs several parameters.

Contents    Page-10    Prev    Next    Page+10    Index