Section 3

Programs are Function and Variable Definitions

Main and auxilliary functions can appear in any order in the definitions window. The only requirement on definition order is that test cases using the function must appear after the main and auxilliary function definitions.

3.1  Composing Functions - no notes

No DrScheme notes for this section.

3.2  Variable Definitions

When you are defining only functions, the order of definitions does not matter. However, the order for variable definitions is significant, because DrScheme evaluates the right-hand side immediately, without looking at the remaining definitions. Therefore,

(define RADIUS 5)
(define DIAMETER (* 2 RADIUS))

is fine, but
(define DIAMETER (* 2 RADIUS))
(define RADIUS 5)

produces the error ``reference to undefined identifier: RADIUS''. DrScheme does not yet know the definition of RADIUS when it tries to evaluate (* 2 RADIUS).

3.3  Finger Exercises on Composing Functions

Exercise Notes

Exercise 3.3.1 Three dots in a row, ..., is a legal Scheme name. DrScheme does not attempt to determine the meaning of a name until necessary. For this reason, you can type in temporary definitions for all of the functions like this:

(define (feet->yards f)
  ...)

Then, one at a time, replace ... in each function and test it.