summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--one/seven.scm18
1 files changed, 17 insertions, 1 deletions
diff --git a/one/seven.scm b/one/seven.scm
index 66e06d9..cc3c7b9 100644
--- a/one/seven.scm
+++ b/one/seven.scm
@@ -3,7 +3,10 @@
;;; <https://creativecommons.org/licenses/by-sa/4.0/>.
(define-module (one seven)
- #:export (tolerances-and-sqrt))
+ #:export (tolerances-and-sqrt
+ good-enough-alt?
+ sqrt-iter-alt
+ sqrt-sicp-alt))
(use-modules (one six))
@@ -28,3 +31,16 @@
(cons tolerance custom-sqrt)
(cons (cons tolerance custom-sqrt)
(tolerances-and-sqrt x (/ tolerance 10))))))
+;;; start excercise 1.1.7
+(define (good-enough-alt? guess prev-guess)
+ (< (abs (- guess prev-guess)) 0.001))
+
+(define (sqrt-iter-alt guess prev-guess x)
+ (if (good-enough-alt? guess prev-guess)
+ guess
+ (sqrt-iter-alt (improve guess x) guess
+ x)))
+
+(define (sqrt-sicp-alt x)
+ (sqrt-iter-alt 1.0 2.0 x))
+;;;; end excercise 1.1.7