Function template for compound input types
Suppose the data definition for the input reveals that one (or more) of the
input parameters is of a compound data type, e.g.
; Data definition:
; A student is a symbol (name), an integer (ID), and a number (GPA)
(define-struct student (name ID GPA))
I recommend
that after writing a define-struct, you immediately
write down the contracts for all the functions that it defines for you,
so the above example becomes
; Data definition:
; A student is a symbol (name), an integer (ID), and a number (GPA)
(define-struct student (name ID GPA))
; make-student: symbol, integer, number => student
; student-name: student => symbol
; student-ID: student => integer
; student-GPA: student => number
; student?: object => boolean
Now the definition of a function that takes a student parameter
looks like
(define (func-for-student the-student)
... (student-name the-student) ...
... (student-ID the-student) ...
... (student-GPA the-student) ...)
Note again that these expressions may actually be used in a different order,
and they may not all appear at all. If a particular field isn't
relevant to the function you're writing, you will of course cross it
out.
Last modified:
Fri Nov 5 14:40:48 EST 1999
Stephen Bloch / sbloch@adelphi.edu