II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
NOTES ON DATA STRUCTURING 97<br />
values of a variable, and the interpretati<strong>on</strong> of each such value; and to permit<br />
subsequent design of an efficient representati<strong>on</strong>.<br />
In particular, in many computer programs an integer is used to stand not<br />
for a numeric quantity, but for a particular choice from a relatively small<br />
number of alternatives. In such cases, the annotati<strong>on</strong> of the program usually<br />
lists all the possible alternative values, and gives the intended interpretati<strong>on</strong><br />
of each of them. It is possible to regard such a quantity as bel<strong>on</strong>ging to a<br />
separate type, quite distinct from the integer type, and quite distinct from<br />
any other similar set of markers which have a different interpretati<strong>on</strong>. Such<br />
a type is said to be an enumerati<strong>on</strong>, and we suggest a standard notati<strong>on</strong> for<br />
declaring the name of the type and associating a name with each of its<br />
alternative values"<br />
type suit = (club, diam<strong>on</strong>d, heart, spade);<br />
ordered type rank = (two, three, four, five, six, seven, eight, nine, ten, Jack,<br />
Queen, King, Ace);<br />
type primary colour = (red, yellow, blue);<br />
ordered type day of week = (M<strong>on</strong>day, Tuesday, Wednesday, Thursday,<br />
type day of m<strong>on</strong>th = 1.. 31 ;<br />
Friday, Saturday, Sunday);<br />
ordered type m<strong>on</strong>th = (Jan, Feb, March, April, May, June, July, Aug, Sept,<br />
Oct, Nov, Dec);<br />
type year = 1900.. 1969;<br />
type Boolean = (false, true);<br />
ordered type floor = (basement, ground, mezzanine, first, sec<strong>on</strong>d);<br />
type coordinate = 0.. 1023;<br />
Our first two examples are drawn from the realm of playing cards. The first<br />
declarati<strong>on</strong> states that club, diam<strong>on</strong>d, heart, and spade are suits; in other<br />
words, that any variable or expressi<strong>on</strong> of type suit can <strong>on</strong>ly denote <strong>on</strong>e of<br />
these four values; and that the identifiers "club .... heart" "diam<strong>on</strong>d" and<br />
"spade" act as c<strong>on</strong>stants of this type. Similarly, the definiti<strong>on</strong> of the type<br />
rank displays the thirteen c<strong>on</strong>stants denoting the thirteen possible values of<br />
the type. In this case it is natural to regard the type as ordered. The next<br />
examples declare the names of the primary colours and of the days of the<br />
week. In c<strong>on</strong>sidering the days of the m<strong>on</strong>th, it is inc<strong>on</strong>venient to write out<br />
the thirty-<strong>on</strong>e possible values in full. We therefore introduce the c<strong>on</strong>venti<strong>on</strong><br />
that a..b stands for the finite range of values between a and b inclusive.<br />
This is known as a subrange of the type to which a and b bel<strong>on</strong>g, in this case