----------------------------------------------------------------- 1) Write a higher-order procedure ADD-EXCEPTION that takes three arguments: two numbers (N1 and N2) and a procedure (FN). ADD-EXCEPTION returns a procedure which behaves exactly like FN except when the argument is equal to N1 in which case it returns N2. As an example consider the procedure USUALLY-SQUARE below: > (define (square x) (* x x)) > (define usually-square (add-exception 42 0 square)) > (usually-square 5) 25 > (usually-square 0) 0 > (usually-square 40) 1600 > (usually-square 42 0 ----------------------------------------------------------------- 2) Is there any difference between the following definitions of PI? Explain your answer. (define pi (/ 22 7)) (define pi (lambda () (/ 22 7))) ----------------------------------------------------------------- 3) What are the values of the folliwng expressions? 1) ((f g) 0) 2) ((f (f g)) 0) where f and g are defined as follows: (define (f h) (lambda (x) (h (h (h x))))) (define (g x) (+ 1 x)) ----------------------------------------------------------------- 4) Write a function that returns the result of converting a temperture i Fahrenheit to its equivalent in Celsius. Use the formula: celsius = (fahrenheit - 32) * 5/9 ----------------------------------------------------------------- 5) Write a procedure named PERFECT? that tests whether a given integer is a perfect number. Like this: > (perfect? 5) #f > (perfect? 6) #t > (perfect? 28) #t Perfect numbers are numbers that are equal to the sum of their devisors. Note, for example, that 6=1+2+3 and 28=1+2+4+7+14. Another interesting fact that one may exploit in this problem is that a devisor of a number N is at most N/2. ----------------------------------------------------------------- 6) Assume the following definitions: (define x 10) (define y 20) What are the values of the following expressions: (let ((x 11)) (+ x y)) (let ((x y) (y x)) (+ x y)) (let ((x y)) (let ((y x)) (+ x y))) -----------------------------------------------------------------