some solutions for MIT Press's "structure and interpretation of computer programs", I guess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
619 B

;; returns a procedure that takes a guess and keeps improving
;; until good enough
(define (iterative-improve good-enough? improve)
(lambda (guess x) ; alternatively: (lambda (guess) (lambda (x) ...))
(define (iter guess)
(if (good-enough? guess x)
(iter (improve guess x))))
(iter guess)))
(define (square x)
(* x x))
(define (average x y)
(/ (+ x y) 2))
(define (nice-sqrt guess x)
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
(define (improve guess x)
(average guess (/ x guess)))
((iterative-improve good-enough? improve) guess x))