Consider the following Pascal program:
1 1 PROGRAM MAIN(OUTPUT); VAR F:TEXT; I:INTEGER;
2 2 BEGIN
3 2 REWRITE(F);
4 3 FOR I := 10 TO 30 DO BEGIN
5 3 WRITELN( I, ’:’, ’ABCDEFGHIJ’ : I);
6 3 WRITELN(F, I, ’:’, ’ABCDEFGHIJ’ : I);
7 2 END;
8 2 RESET(F);
9 2 WRITELN(’--------------------’);
10 3 WHILE NOT EOF(F) DO BEGIN
11 3 WRITE(F^);
12 3 GET(F)
13 3 END
14 0 END.
The program writes a staircase of ABCDEFGHIJ
to the standard output and to a local temporary file, then writes a separator line and copies the local file character by character to the standard output. The expectation is that there will be two copies of the staircase of ABCDEFGHIJ
; however, the result on the BESM-6 is
10:ABCDEFGHIJ
11: ABCDEFGHIJ
12: ABCDEFGHIJ
13: ABCDEFGHIJ
14: ABCDEFGHIJ
15: ABCDEFGHIJ
16: ABCDEFGHIJ
17: ABCDEFGHIJ
18: ABCDEFGHIJ
19: ABCDEFGHIJ
20: ABCDEFGHIJ
21: ABCDEFGHIJ
22: ABCDEFGHIJ
23: ABCDEFGHIJ
24: ABCDEFGHIJ
25: ABCDEFGHIJ
26: ABCDEFGHIJ
27: ABCDEFGHIJ
28: ABCDEFGHIJ
29: ABCDEFGHIJ
30: ABCDEFGHIJ
--------------------
10:ABCDEFGHIJ
15: ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ
CDEFGHIJ
HIJ
To put it mildly, only the first line is correct, the rest is garbage.
To achieve the expected result, it is necessary to write
11 3 IF EOLN(F) THEN WRITELN ELSE WRITE(F^);
Or, given that the internal character encoding is almost ASCII, IF F^ = CHR(10) THEN ...
also works.
In Programming in Pascal
By Nell B. Dale, 1997 (search for eoln
, there are only 5 occurrences), it is unclear if explicitly writing an eoln
character to the standard output is guaranteed to be functionally equivalent to writeln
on all platforms.
Theoretically, even on MS-DOS the internal files, including files of type text
, could be treated as binary, and writeln
to these files would write just chr(10)
; the standard output would be treated as text, and writeln
to it would write chr(13), chr(10)
; and for efficiency, there would be no checking for chr(10)
appearing in the items being output; thus resulting in an incorrect text file if an equivalent program is run.
Would that be a conforming behavior?
A related issue: when reading from the standard input ("punched cards"), eoln(input)
becomes true after 80 of get(input)
, but at that moment input^
is a space character rather than the line feed. If that is conforming, then the first question would thus be answered in the positive as well.