20.03.2013 Views

II. Notes on Data Structuring * - Cornell University

II. Notes on Data Structuring * - Cornell University

II. Notes on Data Structuring * - Cornell University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

NOTES ON DATA STRUCTURING 107<br />

In inspecting or processing a structured value, it is often required to make<br />

many references to its comp<strong>on</strong>ents within a single small regi<strong>on</strong> of code.<br />

In such a case it is c<strong>on</strong>venient to use a with c<strong>on</strong>structi<strong>on</strong><br />

with sv do S;<br />

where sv names the structured variable (or expressi<strong>on</strong>) and S is a program<br />

statement defining what is to be d<strong>on</strong>e with it. Within the statement S, the<br />

comp<strong>on</strong>ents of sv will be referred to simply by their selector names, s 1,- •., sn,<br />

instead of by the usual c<strong>on</strong>structi<strong>on</strong>'sv.sl, sv.s2,...sv.sn. The reas<strong>on</strong>s for<br />

using this c<strong>on</strong>structi<strong>on</strong> are:<br />

(1) To clarify the purpose of the secti<strong>on</strong> of program.<br />

(2) To abbreviate its formulati<strong>on</strong>.<br />

(3) To indicate the possibility of improved efficiency of implementati<strong>on</strong>.<br />

Example" Given today" date, test whether it is a valid date or not.<br />

with today do case m of<br />

{Sept:April :June: Nov:<br />

if day > 30 then go to invalid,<br />

Feb:if day > (if (y + 4) x 4 = y then 29 else 28)<br />

then go to invalid,<br />

else do nothing }.<br />

Exercise<br />

Write functi<strong>on</strong>s to represent the four standard arithmetic operati<strong>on</strong>s <strong>on</strong><br />

complex numbers.<br />

4.2. REPRESENTATION<br />

The standard method of representing a value of Cartesian product type is<br />

simply by juxtaposing the values of its comp<strong>on</strong>ents in a c<strong>on</strong>secutive regi<strong>on</strong> of<br />

store, usually in the order indicated. However, there is c<strong>on</strong>siderable variati<strong>on</strong><br />

in the amount of packing and padding which may be involved in the juxta-<br />

positi<strong>on</strong>. In the standard unpacked representati<strong>on</strong>, each comp<strong>on</strong>ent value is<br />

made to occupy an integral number of words, where a word is the smallest<br />

c<strong>on</strong>veniently addressable and efficiently accessible unit of storage <strong>on</strong> the<br />

computer.<br />

If the values can fit into less storage than <strong>on</strong>e word, there is the opti<strong>on</strong> of<br />

packing more than <strong>on</strong>e comp<strong>on</strong>ent into a word. In a tightpacked repre-<br />

sentati<strong>on</strong>, the bitpatterns of the comp<strong>on</strong>ents are directly juxtaposed. In a<br />

loosely packed representati<strong>on</strong>, the comp<strong>on</strong>ents may be fitted within certain<br />

subdivisi<strong>on</strong>s of a word, which are "natural" in the sense that special machine<br />

code instructi<strong>on</strong>s are available for selecting or updating particular parts of a<br />

word--for example, character boundaries, or instructi<strong>on</strong> fields of a word.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!