11.04.2015 Views

Newsletter #9-#10 - Moorecad.com

Newsletter #9-#10 - Moorecad.com

Newsletter #9-#10 - Moorecad.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

What is a Textfile?<br />

The PASCAL revised report, section 6.2.4 in particular, is in serious<br />

error as to the nature of textfiles.<br />

by -- the definition of type TEXT as FILE OF CHAR.<br />

This error arises -- or is demonstrated<br />

(As a typographicalconvention,<br />

program fragments are presented in upper case, and the pointer operator,<br />

up-arrow, is representedby the character @).<br />

As a result of this lapse,<br />

<strong>com</strong>plex special-casenotions are introduced as primitive concepts. Please<br />

notice that I am not advocating a change in the language, or an abolition of<br />

existing notation:<br />

definition of the textfile notion.<br />

First, consider the files F and G:<br />

F: TEXT;<br />

G: FILE OF FILE OF CHAR.<br />

I merely propose a new, more useful, understanding and<br />

Obviously, a READ or WRITE performed on F will perform the same on G@, the<br />

"inner" file in G. Some of the auxiliary r/o constructs, however~ change in<br />

a very enlightening fashion: reviewing all available literature on the<br />

semantics<br />

of PASCAL file operations, we conclude that<br />

WRITELN(F)<br />

READLN(F)<br />

EOLN(F)<br />

be<strong>com</strong>es<br />

be<strong>com</strong>es<br />

bec ames<br />

PUT (G),<br />

BEGIN WHILE NOT EOF(G@) DO GET(G@): ~ET(G) END, and<br />

EOF(G)!<br />

implied by WRITELN, READLN, and EOLN, a<br />

each line is a file of characters.<br />

We conclude that to supply the structure<br />

textfile is at least a file of lines, where<br />

There is even more to a textfile: we haven't considered the PAGE statement.<br />

Let's add another<br />

declaration:<br />

H: FILE OF FILE. OF FILE OF CHAR.<br />

Now, anywhere we used G, we can use H@:<br />

of READLNchanges.<br />

the addition of the PAGE statement:<br />

logically, however, the re-representation<br />

The wholeset of equivalentconstruct-pairs be<strong>com</strong>es,with<br />

WRITELN(F)<br />

EOLN(F)<br />

PAGE(F)<br />

PUT(H@),<br />

EOF(H@),.and<br />

PUT(H).<br />

At this point, we have developed the structure that is necessary and<br />

sufficient to support all the standard textfile operations. As an added<br />

benefit (or is it a side effect?) we have a better appreciation of the<br />

embedded file, or file-of-file, concept. Before running off to reimplement<br />

textfiles the new way into your favorite <strong>com</strong>piler, however, let's give some<br />

thought to extensibility.<br />

If a textfile is considered as merely a nest of files, then those<br />

implementations which would like to give access to such things as page<br />

numbers, line numbers, and vertical printer spacing ("carriage control") will<br />

have to kludge those features in as primitives: thus we would be back where<br />

we started. If, however, we consider TEXT to be predeclared as follows,<br />

we notice some nice hooks:<br />

TYPE TEXT: RECORD<br />

END;<br />

END<br />

(*EXTERNAL FILE NAME, ETC*)<br />

P :FILE OF RECORD<br />

(*PAGENUMBER*)<br />

L:FILE OF RECORD<br />

END<br />

(*LINENUMBER*)<br />

(*SPACING*)<br />

C:FILE OF CHAR<br />

The <strong>com</strong>ments point out places where interesting implementation-dependent<br />

features caD reside.<br />

READ (F) .;.<br />

WRITE (F)<br />

READLN(F)<br />

READ(H@@),<br />

WRITE(H@@),<br />

BEGIN WHILE NOT EOF(H@@) D0 GET(H@@):<br />

IF NOT EOF(H) THEN<br />

William C. Price<br />

28282 SW Mountain Rd.<br />

West Linn, OR 97068 USA<br />

(* Received 77/06/10 *)<br />

IF EOF(H@) THEN GET(H) ELSE GET(H@)<br />

END,<br />

WCP:pt<br />

- 1 -<br />

- 2 -

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

Saved successfully!

Ooh no, something went wrong!