Skip to content

Instantly share code, notes, and snippets.

@oscardelben
Created March 19, 2009 08:10
Show Gist options
  • Save oscardelben/81643 to your computer and use it in GitHub Desktop.
Save oscardelben/81643 to your computer and use it in GitHub Desktop.
Exercise 1.2
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
(* (* 3 (- 6 2)) (- 2 7)))
Exercise 1.3
(define (sum-of-high-squares a b c)
(+ (if (> a b) a b) (if (> b c) b c)))
Exercise 1.4
The if expression returns either + or - which can be used as operand.
Exercise 1.5
If the interpreter is using normal order evaluation, the test returns 0, else the test will evaluate either the first parameter and the second, resulting in an infinite loop.
Exercise 1.6
When Alyssa attempts to compute the square root with new-if the program acts as if we were using if.
Exercise 1.7
For small numbers, checking for a difference below 0.001 is not enough while for big numbers it's a waste of resources.
Below an improved version of good-enough:
(define (good-enough? guess old-guess x)
(< (abs (- guess old-guess)) (/ guess 10000)))
Exercise 1.8
(define (improve guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess))
3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment