<< Previous exercise (1.45) | Index | Next exercise (2.1) >>

Note that the arguments to *iterative-improve* must:

- tell if
*a guess*is**good enough** - improve a guess

(define (iterative-improve good-enough? improve) (lambda (guess) (if (good-enough? guess) guess ((iterative-improve good-enough? improve) (improve guess))))) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (fixed-point f first-guess) ((iterative-improve (lambda (x) (close-enough? x (f x))) f) first-guess)) (define (sqrt x) ((iterative-improve (lambda (y) (< (abs (- (square y) x)) 0.0001)) (lambda (y) (average y (/ x y)))) 1.0))

Here is a cleaner version of *iterative-improve* that reduces the number of state variables from three to one by using an inner procedure *iter*.

```
(define (iterative-improve good-enough? improve)
(lambda (first-guess)
(define (iter guess)
(if (good-enough? guess)
guess
(iter (improve guess))))
(iter first-guess)))
```

You can make it even cleaner by simply returning the inner procedure

```
(define (iterative-improve good-enough? improve)
(lambda (first-guess)
(define (iter guess)
(if (good-enough? guess)
guess
(iter (improve guess))))
iter))
```

You can make it even cleaner by removing the unnecessary lambda

```
(define (iterative-improve good-enough? improve)
(define (iter guess)
(if (good-enough? guess)
guess
(iter (improve guess))))
iter)
```