This shows you the differences between two versions of the page.
| — |
exercise_1.34 [2009/03/02 01:32] (current) 204.14.159.185 created |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | // | ||
| + | Suppose we define the procedure | ||
| + | // | ||
| + | <code> | ||
| + | (define (f g) | ||
| + | (g 2)) | ||
| + | </code> | ||
| + | // | ||
| + | Then we have | ||
| + | // | ||
| + | <code> | ||
| + | (f square) | ||
| + | 4 | ||
| + | (f (lambda (z) (* z (+ z 1)))) | ||
| + | 6 | ||
| + | </code> | ||
| + | // | ||
| + | What happens if we (perversely) ask the interpreter to evaluate the combination (f f)? Explain. | ||
| + | // | ||
| + | |||
| + | Answer: | ||
| + | Failure, because (f f) evaluates to (f 2), | ||
| + | but then we get (2 2); the first 2 is not a function so the interpreter fails. | ||