Today’s post comes after the heading “What Is Meant By Data?” The context is a rational number arithmetic package introduced at the beginning of the chapter.
We began the rational-number implementation in section 2.1.1 by implementing the rational-number operations
sub-rat, and so on in terms of three unspecified procedures:
denom. At that point, we could think of the operations as being defined in terms of data objects — numerators, denominators, and rational numbers — whose behavior was specified by the latter three procedures.
But exactly what is meant by data? It is not enough to say “whatever is implemented by the given selectors and constructors.” Clearly, not every arbitrary set of three procedures can serve as an appropriate basis for the rational-number implementation. We need to guarantee that, if we construct a rational number
xfrom a pair of integers
d, then extracting the
denomof x and dividing them should yield the same result as dividing
d. In other words,
denommust satisfy the condition that, for any integer
nand any non-zero integer
(make-rat n d), then
(numer x) n --------- = - (denom x) d
In fact, this is the only condition
denommust fulfill in order to form a suitable basis for a rational-number representation. In general, we can think of data as defined by some collection of selectors and constructors, together with specified conditions that these procedures must fulfill in order to be a valid representation.