Feb 25, 2008

Square Roots by Newton's Method.

Square Roots by Newton's Method.

(define (sqrt x)
(define (good-enough? guess)
(< (abs (- (square guess) x)) 0.001))
(define (improve guess)
(average guess (/ x guess)))
(define (sqrt-iter guess)
(if (good-enough? guess)
guess
(sqrt-iter (improve guess))))
(sqrt-iter 1.0))

"x" is a free variable in the internal definitions.It gets its value from the argument with which the enclosing procedure sqrt is called.This dicipline is called "lexical scoping".

No comments: