[Oberon] LOOP conversion

Joerg joerg.straube at iaeth.ch
Mon Jan 4 11:28:27 CET 2021


This is exactly a reason why LOOP/EXIT shouldn't be allowed by the compiler not even for "porting" reasons __
Jörg

Am 04.01.21, 11:21 schrieb "Oberon im Auftrag von Chris Burrows" <oberon-bounces at lists.inf.ethz.ch im Auftrag von chris at cfbsoftware.com>:

    > -----Original Message-----
    > From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
    > Bernhard Treutwein
    > Sent: Monday, 4 January 2021 7:46 PM
    > To: oberon at lists.inf.ethz.ch
    > Subject: [Oberon] LOOP conversion
    > 
    > Our russian friends had a very long thread about conversion of LOOP -
    > EXIT
    > 	https://forum.oberoncore.ru/viewtopic.php?f=82&t=2547
    > it is readable and understandable with Google translate ...
    > 
    > I personally think that deliberate and good use of LOOP is not that
    > bad.
    > 
    > E.g., I find
    > 
    > LOOP
    >   Step;
    >   IF cond THEN EXIT END;
    >   CodeBlock
    > END
    > 
    > more attractive and readable than
    > 
    > Step;
    > WHILE ~cond DO
    >   CodeBlock;
    >   Step
    > END
    > 

    Here's a trickier example for anybody who is up for a challenge. It was
    found in ETH Oberon - TextFrames.Menu:

         IF SmallDisplay & (Display.Width < 1024) THEN (*adjust commands*)
           mb := 0; me := 0; s := 0; d := 0;
           LOOP
             (*position to beginning of word*)
             LOOP
               IF s >= LEN(commands) THEN EXIT END;
               ch := commands[s]; INC(s);
               IF ch = 0X THEN EXIT END;
               commands[d] := ch; INC(d);
               IF ("A" <= CAP(ch)) & (CAP(ch) <= "Z") THEN EXIT END
             END;
             IF (s >= LEN(commands)) OR (ch = 0X) THEN EXIT END;
             (*scan first part of word, checking against last module name*)
             m := mb; i := 0;
             LOOP
               INC(i); IF (m < me) & (commands[m] = ch) THEN INC(m) END;
               IF s >= LEN(commands) THEN EXIT END;
               ch := commands[s]; INC(s);
               IF ch = 0X THEN EXIT END;
               commands[d] := ch; INC(d);
               IF (ch < "0") OR ("9" < ch) & (CAP(ch) < "A")
                    OR (CAP(ch) > "Z") THEN EXIT
               END
             END;
             (*check for match*)
             IF (s < LEN(commands)) & (ch = ".") THEN
               IF m = mb + i THEN (*matches previous module name - compress*)
                 DEC(d, i); commands[d-1] := "."
               ELSE (*set new module name*)
                 mb := d - (i+1); me := d-1
               END;
               (*and do last part of word*)
               LOOP
                 IF s >= LEN(commands) THEN EXIT END;
                 ch := commands[s]; INC(s);
                 IF ch = 0X THEN EXIT END;
                 commands[d] := ch; INC(d);
                 IF (ch < "0") OR ("9" < ch) & (CAP(ch) < "A")
                      OR (CAP(ch) > "Z") THEN EXIT
                 END
               END
             END;
            IF (s >= LEN(commands)) OR (ch = 0X) THEN EXIT END
           END;
           IF d < LEN(commands) THEN commands[d] := 0X END
         END;
       END;

    I'd be interested to know how long it takes you - including the time taken
    to prove to yourself that your conversion is identical in functionality.

    Regards,
    Chris

    Chris Burrows
    CFB Software
    https://www.astrobe.com

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




More information about the Oberon mailing list