Exercise 1.34

Question

Suppose we define the procedure

(define (f g) (g 2))

Then we have

(f square)
; 4

(f (lambda (z) (* z (+ z 1))))
; 6

What happens if we (perversely) ask the interpreter to evaluate the combination (f f)? Explain?

Answer

(define (f g) (g 2))

; becomes
(f 2)
; becomes
(2 2)

Which returns the error Wrong type to apply: 2 because 2 is not a procedure, so it yields invalid syntax.