SICP实例 1.1.7 (求平方根)
(define (sqrt-iter guess x)
(if (good-enough? guess x)
guess
(sqrt-iter (improve guess x)
x)))
(define (improve guess x)
(average guess (/ x guess)))
(define (average x y)
(/ (+ x y) 2))
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
(define (sqrta x)
(sqrt-iter 1.0 x))
(define (square x)
(* x x))
(sqrta 9)
(sqrt 9)
我用的两个版本都是自带了sqrt函数,而不自带square函数.
所以把sqrt改成sqrta,然后自己实现square函数.
函数名里加了个问号,我还以为有三目表达式呢