[Oberon] Eliminating RETURN statements
chris at cfbsoftware.com
Thu Apr 9 14:26:01 CEST 2020
Not only that but the generated instructions are identical which proves that the two forms are equivalent.
However, the number of operators could be reduced by transforming it into a REPEAT statement. For example:
PROCEDURE Fit(i, j: INTEGER): BOOLEAN;
VAR k: INTEGER;
k := -1;
UNTIL (k > piecemax[i]) OR (p[i, k] & puzzl[j + k]);
RETURN k > piecemax[i]
Personally I find that the absence of the NOTs make it easier to comprehend,
> -----Original Message-----
> From: Jörg [mailto:joerg.straube at iaeth.ch]
> Sent: Thursday, 9 April 2020 6:55 PM
> To: ETH Oberon and related systems; Chris Burrows
> Subject: Re: [Oberon] Eliminating RETURN statements
> The generated code length of the two solutions is the same.
> ?Am 09.04.20, 09:22 schrieb "Oberon im Auftrag von Hans Klaver" <oberon-
> bounces at lists.inf.ethz.ch im Auftrag von hklaver at dds.nl>:
> Chris Burrows wrote:
> >> PROCEDURE Fit (i, j: INTEGER): BOOLEAN;
> >> VAR k: INTEGER;
> >> BEGIN
> >> k := 0;
> >> WHILE (k <= piecemax[i]) & ~(p[i, k] & puzzl[j + k]) DO
> >> INC(k)
> >> END
> >> RETURN k > piecemax[i]
> >> END Fit;
> > According to one of De Morgan's Laws
> > i.e. ~(A AND B) --> (~A OR ~B)
> > the WHILE expression can be simplified to:
> > WHILE (k <= piecemax[i]) & (~p[i, k] OR ~puzzl[j + k]) DO
> > However, I'm not convinced this is simpler. What do you think?
> I would say that simplification means 'bringing to a form with less
> operators', and here there are (slightly) more operators on the right side.
> So I do not consider it a simplification.
> Hans Klaver
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
More information about the Oberon