[Oberon] Tidyness of iteration.

John R. Strohm strohm at airmail.net
Tue Nov 15 01:01:19 CET 2016


Depending on the definition of R.eot after Texts.OpenReader(R, t, 0) but 
before Texts.Read(R, ch), you MIGHT be able to get away with this:

(* Using WHILE, Texts.Read is duplicated. *)
PROCEDURE WHILEiteration();
BEGIN
  Texts.OpenReader(R, t, 0);
  WHILE ~R.eot
    (* Process ch *);
    Texts.Read(R, ch)
  END
END WHILEinteration.

Wirth originally defined (or tried to define) READ() and EOF() in PASCAL to 
(at least attempt to) work this way.

-----Original Message----- 
From: peter at easthope.ca
Sent: Monday, November 14, 2016 12:18 PM
To: oberon at lists.inf.ethz.ch
Subject: [Oberon] Tidyness of iteration.

(* Pre-2013. *)
PROCEDURE LOOPiteration();
BEGIN
Texts.OpenReader(R, t, 0);
LOOP
Texts.Read(R, ch);
IF R.eot THEN EXIT ELSE (* Process ch *) END
END
END LOOPinteration.

Project Oberon 2013, Page 5.
"2. The LOOP and EXIT statements (repetitions with multiple exit points) 
have been discarded."

(* Using REPEAT, R.eot must be checked twice in each iteration. *)
PROCEDURE REPEATiteration();
BEGIN
Texts.OpenReader(R, t, 0);
REPEAT
IF ~R.eot THEN Texts.Read(R, ch); (* Process ch *) END
UNTIL R.eot
END REPEATinteration.

(* Using WHILE, Texts.Read is duplicated. *)
PROCEDURE WHILEiteration();
BEGIN
Texts.OpenReader(R, t, 0);
Texts.Read(R, ch);
WHILE ~R.eot
(* Process ch *);
Texts.Read(R, ch)
END
END WHILEinteration.

Can the REPEAT example or the WHILE example be simplified further?
(One must wonder about discarding REPEAT and WHILE and retaining LOOP with
strictly one EXIT.)

Thanks,            ... Lyall E.


-- 

123456789 123456789 123456789 123456789 123456789 123456789 123456789
Tel: +1 360 639 0202                      Pender Is.: +1 250 629 3757
http://easthope.ca/Peter.html              Bcc: peter at easthope. ca

--
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
https://lists.inf.ethz.ch/mailman/listinfo/oberon 


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the Oberon mailing list