Exercise 1.9

Posted on Tuesday, September 11th, 2007

(+ 4 5)
(inc (+ 3 5))
(inc (inc (+ 2 5)))
(inc (inc (inc (+ 1 5))))
(inc (inc (inc (inc (+ 0 5)))))
(inc (inc (inc (inc 5))))
(inc (inc (inc 6)))
(inc (inc 7))
(inc 8)
9

(+ 4 5)
(+ 3 6)
(+ [...]

continue reading

Exercise 1.8

Posted on Thursday, September 6th, 2007

(define (cubert x)
(cube-iter 1.0 x))

(define (cube-iter guess x)
(if (good-enough? guess x)
guess
(cube-iter (improve guess x)
[...]

continue reading

Exercise 1.7

Posted on Thursday, September 6th, 2007

Tests that show the problem:
For small numbers – it’s off, large numbers seem to be stuck in an infinite loop.

> (sqrt (square .00001))
0.03125000106562499
> (sqrt (square 10000000))
– endless loop
The reason the small numbers fail is [...]

continue reading

Exercise 1.6

Posted on Thursday, September 6th, 2007

I cheated but it makes sense now, I think. Since the interpreter uses applicative-order evaluation it will attempt to solve all the parameters before substituting them in to the new-if function. Since the [...]

continue reading

Exercise 1.5

Posted on Thursday, September 6th, 2007

applicative-order evaluation: The interpreter would enter an endless loop because it would try to evaluate (p) before it evaluates test. (p) = (p) = (p) and so on.
normal-order evaluation: The interpreter would return 0 [...]

continue reading

Exercise 1.4

Posted on Thursday, September 6th, 2007

0

continue reading

Exercise 1.3

Posted on Thursday, September 6th, 2007

(define (sos-larger2 a b c)
(cond ((and (< a b) (< a c)) (sos b c))
((and (< b a) (< b c)) (sos a c))
[...]

continue reading

Exercise 1.2

Posted on Thursday, September 6th, 2007

(/ (+ 5 4
(- 2
(- 3
(+ 6 (/ [...]

continue reading

Exercise 1.1

Posted on Thursday, September 6th, 2007

> 10
10
> (+ 5 3 4)
12
> (- 9 1)
8
> (/ 6 2)
3
> (+ (* 2 4)(- 4 6))
6
> (define a 3)
> (define b (+ a 1))
> (+ a b (* a b))
19
> (= a b)
#f
> [...]

continue reading
Newer Entries