Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Instructions for students & labbies: Students use DrScheme, following the design recipe, on the exercises at their own pace, while labbies wander among the students, answering questions, bringing the more important ones to the lab's attention.

Quick Review of Scope

A function definition introduces a new local scope - the parameters are defined within the body.

  • (define (parameters...) body)

A local definition introduces a new local scope - the names in the definitions are defined within both within the bodies of the definitions and within the local's body.

  • Wiki Markup
    (local \[definitions...\] body)

Wiki Markup
Note that the use of square brackets \[ \] here is equivalent to parentheses( ).  The brackets help set off the definitions a little more clearly for readability.

In order to use local and the other features about to be introduced in class, you need to set the DrScheme language level to "Intermediate".

Exercises

Finding the maximum element of a list.

Let's consider the problem of finding the maximum number in a list. In general, there's an issue answering "What is the maximum number in an empty list?" To simplify the problem for today's goal, we'll only use non-negative numbers, and define the maximum number of the empty list to be zero. (Alternatively, we could write the function only for non-empty lists.)

  • Develop the function without using local. For the purposes of this exercise, do not use any helper functions, nor the
    built-in Scheme function max.

Stylisticallywhat Stylistically what don't (or shouldn't) you like about this code?

  • Develop the function

...

  • using local. Again, don't use a helper function,

...

  • or max.

Try running each version on the following input (or longer ones):

...

(list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)

...

For each version, determine how many calls to your function is made
for the input

HTML

(list 1 2 3 ...

...