A Better Way
Recall a Scheme procedure application:
(procedure arg1 arg2 ... argn )
All elements of the application, including the procedure itself, are evaluated.
(define operate +)
(operate 3 4) ⇒ 7
Thus a procedure can be given to another
procedure as an argument (as data), and then
applied to other data (as a program):
(define arithmetic
(lambda (operate arg1 arg2)
(operate arg1 arg2)))
Now any of the following will work:
(arithmetic + 3 4) → 7
(arithmetic * 3 4) → 12
(arithmetic remainder 30 4) → 2
(arithmetic / 45 17) → 2 11/17
(arithmetic expt 3 4) → 81
Q: Will only arithmetic procedures work?