[Oberon] Eliminating RETURN statements
Hans Klaver
hklaver at dds.nl
Fri Apr 10 01:46:07 CEST 2020
Chris Burrows wrote:
> 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;
> BEGIN
> k := -1;
> REPEAT
> INC(k)
> UNTIL (k > piecemax[i]) OR (p[i, k] & puzzl[j + k]);
> RETURN k > piecemax[i]
> END Fit;
>
> Personally I find that the absence of the NOTs make it easier to comprehend,
Chris, I fully agree. Very elegant! The code can even be made slightly more elegant:
(...)
UNTIL (k > piecemax[i]) OR p[i, k] & puzzl[j + k]
RETURN k > piecemax[i]
END Fit;
One of the nice things of Oberon is that the precedence of the logical operators is emphasized by their size.
Because OR is larger than & , which is larger than ~ , it is easy to remember that
a OR ~b & c equals (a) OR ((~b) & c)
The smaller the operator the more it 'binds' to the operand(s). The ~ operator binds most and so is evaluated first, the next in size, &, binds more than the larger OR and so & is evaluated before OR, which 'separates' its operands most and so is evaluated last. Easy!
--
Hans Klaver
More information about the Oberon
mailing list