may be the returned
value of a procedure call, and thus may be the value produced by evaluating an
expression.
Goals:
- Write procedures which take one or more procedure arguments
- Write procedures which return a procedure as return value.
- Write procedures which do both.
- Experience the use and combination of such procedures.
- Recognize the power to express higher order abstractions through
these "first class" properties of procedures.
Reading: SICP (Structure and Interpretation of Computer Programs), Section 1.3
Warning: For these exercises you must set your language to "advanced student"
or higher.
Homework exercises (Due at start of lab 2 Mar 01):
-
SICP Exercise 1.30 (iterative sum procedure)
-
SICP Exercise 1.31 (product procedure)
-
SICP Exercise 1.32, part (a) only. (accumulate procedure - even higher order).
-
SICP Exercise 1.41 (doubler)
Note: inc is not a built-in scheme procedure.
Use (define inc (lambda (x) (+ x 1))) .
About (((double (double double)) inc) 5): ...Whew! Can you follow what happens?!
Try to follow through the steps of what happens when you do the
suggested use of double . Unfortunately you cannot use the stepper,
which is not available in the advanced student language.
You must mentally step through the evaluation process.
Module D Flourishes (these are optional problems):
-
SICP Exercise 1.36 (fixed-point with and without average damping)
Use the stepper instead of inserting display calls, in order
to count the number guesses. That is, take the number of steps to be the
number of times a new guess is created rather than the total number of steps
the stepper creates.
-
SICP Exercise 1.42 (composer)
-
SICP Exercise 1.43 (repeater)
Verify (by some testing) that (double f), of exercise 1.41,
is the same as (repeated f 2).
Don't use only inc for f or only 5 for the initial argument.