[size=medium]
Exercise 1.1 This exercise is very easy, just evaluate some expressions.[/size]
[size=medium]Exercise 1.2 Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
Solution: First, find the smallest number of three numbers. So the result is the sum of the squares of three numbers subtract the square of the smallest number.[/size]
[size=medium]Exercise 1.3 Ben Bitdiddle has invented a test to determine whether the interpreter he is faced with is using applicative-order evaluation or normal-order evaluation. He defines the following two procedures:[/size]
Then he evaluates the expression
[size=medium]What behavior will Ben observe with an interpreter that uses applicative-order evaluation? What behavior will he observe with an interpreter that uses normal-order evaluation? Explain your answer.
[/size]
Exercise 1.1 This exercise is very easy, just evaluate some expressions.[/size]
1 ]=> 10
;Value: 10
1 ]=> (+ 5 3 4)
;Value: 12
1 ]=> (- 9 1)
;Value: 8
1 ]=> (/ 6 2)
;Value: 3
1 ]=> (+ (* 2 4) (- 4 6))
;Value: 6
1 ]=> (define a 3)
;Value: a
1 ]=> (define b (+ a 1))
;Value: b
1 ]=> (+ a b (* a b))
;Value: 19
1 ]=> (= a b)
;Value: #f
1 ]=> (if (and (> b a) (< b (* a b)))
b
a)
;Value: 4
1 ]=> (cond ((= a 4) 6)
((= b 4) (+ 6 7 a))
(else 25))
;Value: 16
[size=medium]Exercise 1.2 Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
Solution: First, find the smallest number of three numbers. So the result is the sum of the squares of three numbers subtract the square of the smallest number.[/size]
(define (sum-of-square-bigers x y z)
(let ((minimum (min x y z)))
(- (+ (square x)
(square y)
(square z))
(square minimum))))
[size=medium]Exercise 1.3 Ben Bitdiddle has invented a test to determine whether the interpreter he is faced with is using applicative-order evaluation or normal-order evaluation. He defines the following two procedures:[/size]
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
Then he evaluates the expression
(test 0 (p))
[size=medium]What behavior will Ben observe with an interpreter that uses applicative-order evaluation? What behavior will he observe with an interpreter that uses normal-order evaluation? Explain your answer.
[/size]