Lab Module D -- Procedures as first class objects

CISC 280 Program Development Techniques

Purpose: In Scheme procedures are first class. That means that like numbers, strings, and other kinds of data, procedures
  • may be the value bound to a name,
  • may be passed as arguments to another procedure,
  • may be the returned value of a procedure call, and thus may be the value produced by evaluating an expression.

    Goals:

    1. Write procedures which take one or more procedure arguments
    2. Write procedures which return a procedure as return value.
    3. Write procedures which do both.
    4. Experience the use and combination of such procedures.
    5. 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):

    1. SICP Exercise 1.30 (iterative sum procedure)

    2. SICP Exercise 1.31 (product procedure)

    3. SICP Exercise 1.32, part (a) only. (accumulate procedure - even higher order).

    4. 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):

    1. 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.

    2. SICP Exercise 1.42 (composer)

    3. 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.