[previous] [up] [next]     [contents]
Next: Finger Exercises on Composing Up: Programs are Function and Previous: Composing Functions- No Notes

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



PLT