Versions Compared

Key

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

...

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.

(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 #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 usinglocalusing local. For the
purposes of this exercise, do not use any helper functions, nor the
built-in Scheme functionmaxfunction max.

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

...

Develop the function usinglocal. Again, don't use a
helper function, ormax.

HTML

...