[Oberon] Bit-fiddling: SETs and type casts in Oberon-07

Chris Burrows cfbsoftware at gmail.com
Sun Aug 7 02:11:42 CEST 2022


On Sun, Aug 7, 2022 at 6:59 AM Hans Klaver <hklaver at dds.nl> wrote:

> Hi all,
>
> While trying to make an Oberon-07 version of the classic predeclared
> function CAP I noticed some differences in the behaviour of the two
> compilers I use regularly.
>


> <snip>
>
> My questions are:
> - the behaviour of which of the two above mentioned existing compilers do
> you like best?
> - do you know an Oberon-07 compiler that can compile CAP0, and what do you
> think of it?
>
>
I don't like any of the proposed solutions but if you are looking for
efficiency over readability try this on both of your compilers:

  PROCEDURE CAP (ch: CHAR): CHAR;
      RETURN SYSTEM.VAL(CHAR, SYSTEM.VAL(SET, ORD(ch)) - {5})
  END CAP;

otherwise my preference would be:

  PROCEDURE CAP(ch: CHAR): CHAR;
   (*
    Capitalizes ASCII lower-case letters while leaving all other characters
unchanged.
   *)
 VAR
    cap: CHAR;
  BEGIN
    IF (ch >= "a") & (ch <= "z") THEN cap := CHR(ORD(ch) - 32) END;
    RETURN cap
  END CAP;

Regards,
Chris Burrows
CFB Software
https://www.astrobe.com/RISC5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20220807/4f454261/attachment.html>


More information about the Oberon mailing list