(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 xy) (/ (+ xy) 2)) (define (good-enough? guess x) (< (abs (- (square guess) x)) 0.0001)) (define (square x) (* xx)) (define (sqrt-g x) (sqrt-iter 1.0 x))
This is a program for sqrt. And the question is when you try to use new-if to replace if with new-if.
(define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter(improve guess x) x)))
It is new if
(define (new-if predicate then-clause else-clause) (cond (predicate then-clause) (else else-clause)))
My opinion is the result of two programs that will be the same. because new-if and if can give the same results.
However, a new one - if proven wrong, because it was a dead circle when I tried.
So why?
source share