Skip to content

EWD249 - 73

LONGREP
begin integer k;
line: {integer array sym[0 : 99]};
lineprint: {k:= 0; while k < 100 do {PRSYM(sym[k]); k plus 1}; NLCR};
lineclear: {k:= 0; while k < 100 do {sym[k]:= space; k plus 1}};
linemark: {sym[x]:= mark}
end

This however leads to an implementation filling out the line with spaces at the righthand side of the rightmost mark: it is like banging the space bar until the bell rings when we want to effect the transition to a new paragraph while writing a letter!

The next version suppresses superfluous PRSYM-commands and even leaves those elements of the variable of type "line" undefined that do not need to be defined. With each line a counter "f" is associated, giving the number of PRSYM-commands to be given for that line. Clearing a line now shrinks into setting "f" to zero!

SHORTREP
begin integer k;
line: {integer f; integer array sym[0 : 99]};
lineprint: {k:= 0; while k < f do {PRSYM(sym[k]); k plus 1}; NLCR};
lineclear: {f:= 0};
linemark: {sym[x]:= mark;
           if f ≤ x do {k:= f; while k < x do {sym[k]:= space; k plus 1};
                        f:= x + 1}}
end

Note added later.

The above program is essentially the program as I have shown it to at least five different audiences. Now, two months later, while thinking at leisure about correctness proofs, I suddenly realize that the given algorithm for "linemark" betrays my past, for it is a piece of lousy coding, compared with the following alternative: