Clarity on line (and page) endings for Algol 68 transput
chris hermansen
clhermansen@gmail.com
Wed Jul 8 20:58:44 GMT 2026
Thanks for the reply Jose,
On Wed, Jul 8, 2026 at 3:12 AM Jose E. Marchesi <jemarch@gnu.org> wrote:
>
> Hi Chris.
>
> > Good afternoon everyone,
> >
> > I am trying to find clarity on "the proper way" of handling of line (and
> > page) endings in Algol 68 transput.
> >
> > Back in the day, I wrote several articles on Algol 68 for
> > https://www.opensource.com. In one, I talked about using closures with
> > "here procedures" to facilitate processing data from delimited text
> files.
> >
> > Doing that, I found that when I wanted to read a line of text I needed to
> > include "newline" in order to skip over line-ending characters; for
> example:
> >
> > file inf;
> > open(inf, input_file_name, stand_in_channel);
> > bool finished_reading := false;
> > on logical file end (inf, (ref file f) bool: finished_reading := true);
> > while
> > string line;
> > get(inf,(line, newline));
> > not_finished_reading
> > do
> > ...
> > od
> >
> > (this was using Algol 68 Genie at that time).
> >
> > However, in McGettrick p.38, I read (for example):
> > --
> > The effect of a read statement such as
> > read((a, b, c, d)
> > is, at least for present purposes, the same as the four read statements
> > read(a); read(b); read(c); read(d)
> >
> > It is convenient therefore to consider only read statements of the form
> > "read(a)" where "a" is a single variable or, more precisely, a single
> > object. The effect of more complex read statements can then be defined
> in
> > terms of the simpler statements.
> >
> > The effect of "read(x)" will now be considered. There are several cases
> to
> > be discussed. These arise from the different possible modes of "x".
> > (i) Suppose "x" has mode "ref int". The input is devoured until the
> first
> > non-blank character is encountered. Newlines are taken if necessary.
> The
> > integer is then read and assigned to the variable "x". It will be
> > terminated by a non-digit character or by a new line, whichever comes
> > first...
> > ...
> > (iv) Suppose "x" has mode ref char. If the reading position is at the
> end
> > of the line, a new line is taken. The first character is read and
> assigned
> > to "x".
> > --
> >
> > This "Newlines are taken if necessary" approach does not seem to match my
> > experience with reading a text file line by line into ref string
> > variables. Explicitly, as I mentioned above, to move to the next line in
> > order to read it, I had to issue a newline.
> >
> > Does anyone have any advice on this matter?
>
> This is specified in the Report:
>
>
> 10.3.3.2. Formatless input
>
>
> [...]
>
> ff) If the mode of N is specified by ref char, then first, if the
> current line is exhausted, a good position is found on a subsequent
> line; next, a character is read and assigned to N.
>
> gg) If the mode of N is specified by ref[]char, then input takes place
> (as in ff) to the subnames of N one after the other (with new lines
> being taken as required).
>
> hh) If the mode of N is specified by ref string, then characters are
> read until either
>
> (i) a character is encountered which is contained in the string
> associated with the file by a call of the routine make_term, or
>
> (ii) the current line is exhausted, whereupon the event routine
> corresponding to on_line_end (or, where appropriate, to on_page_end,
> on_physical_file_end or on_logical_file_end) is called; if the event
> routine moves the current position to a good position, then input of
> characters is resumed.
>
> This is great info, thanks a lot for that. I've reviewed §10.3.3.2 in the
RR and I find the paragraph subsequent to hh-ii) to be also informative:
The string consisting of the characters read is assigned to N (note that, if
the current line has already been exhausted, or if the current position is
at
the start of an empty line or outside the logical file, then an empty string
is assigned to N) .)
I also had another trawl through McGettrick and I see on p. 203 Example
7.1.5b Reading strings of characters:
--
string s, t; read((s,t))
results in t being assigned the empty string since reading into s leaves
the current reading position at the end of a line or the logical end of
file.
--
So generally speaking, when we're reading a string:
- we don't want "on_line_end" to move to the beginning of the next line or
we will end up with the entire contents of the file from the starting
position in the string with no separators between lines;
- therefore we want to use "newline" to advance over the line end if we
intend to read each line of the file into a string.
I also see in RR p.163:
mode ?- in type = c an actual-declarer specifying a mode united from
(2.1.3.6.a} 'reference to flexible row of character' together with a
sufficient set of modes each of which is 'reference to' followed by
a mode which does not contain 'flexible', 'reference to',
'procedure' or 'union of' c;
I had not previously connected all the dots on "does not contain
'flexible'" - ie the only flexible row mode that "get" is prepared to
handle is "string".
Looking more deeply into van Vliet's code for "get" I see that he does in
fact handle ref [] char and string differently.
--
Chris Hermansen · clhermansen "at" gmail "dot" com
C'est ma façon de parler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/algol68/attachments/20260708/b3d3c7e4/attachment.htm>
More information about the Algol68
mailing list