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

joerg.straube at iaeth.ch joerg.straube at iaeth.ch
Sun Aug 7 07:48:28 CEST 2022


We are in heavy grey zone here 😊
First, Oberon-07 does not define any character set. Whether the compiler internally uses US-ASCII, EBCDIC, ISO-5428 (Greek) is not defined by Oberon-07
We only know that CHR and ORD are opposite function and ORD returns an INTEGER. Oberon-07 does not define the size of an INTEGER, so we don’t know how many characters we have. It’s up to the compiler
US-ASCII: ORD(“M”) = 041H
EBCDIC: ORD(“M”) = 0D4H
ISO-5428: ORD(“M”) = 04FH

The only thing in Oberon-07 we know for sure:   ch = CHR(ORD(ch))

Second, what is the definition of CAP?
Does CAP() only convert (so the input is a small letter) or does it check as well?
Let’s assume you want to program a module Strings.Cap(s). Do you write:
i := 0; WHILE s[i] # 0X DO s[i] := CAP(s[i]); INC(i) END;
or do you write
i := 0; WHILE s[i] # 0X DO IF (“a” <= s[i]) AND (s[i] <= “z”) THEN s[i] := CAP(s[i]) END; INC(i) END;

br
Jörg


Von: Oberon <oberon-bounces at lists.inf.ethz.ch> im Auftrag von Chris Burrows <cfbsoftware at gmail.com>
Datum: Sonntag, 7. August 2022 um 03:51
An: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
Betreff: Re: [Oberon] Bit-fiddling: SETs and type casts in Oberon-07


On Sun, Aug 7, 2022 at 11:14 AM Chris Burrows <cfbsoftware at gmail.com<mailto:cfbsoftware at gmail.com>> wrote:

Oops!

 IF (ch >= "a") & (ch <= "z") THEN cap := CHR(ORD(ch) - 32) ELSE cap := ch END;

Third time lucky? ;-)

  PROCEDURE CAP(ch: CHAR): CHAR;
  BEGIN
    IF (ch >= "a") & (ch <= "z") THEN ch := CHR(ORD(ch) - 32) END;
    RETURN ch
  END CAP;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20220807/a43de81e/attachment.html>


More information about the Oberon mailing list