[Oberon] How to write this program in Oberon-07?

Joe Turner medianjoe at mailfence.com
Mon Jan 24 18:27:48 CET 2022


Hi Jorg,

Thanks for the reply. That's a neat solution. I can do that with the string library provided in OBNC. I was wondering how to do it with a CASE statement but it seems quite limited without ELSE. ie, for this example you would have to explicitly list all the values which ch could take (other than vowels). I learned (Turbo) pascal years ago and have recently started programming again. I never really liked the C syntax languages and rather than use Free Pascal I thought I'd give Oberon a try. I wonder if Wirth took minimalism a bit too far in this version though?

January 24, 2022 4:03:08 PM CET "Jörg" <joerg.straube at iaeth.ch> wrote:

Hi Joe

 
LOOP/EXIT might seem handy, but for source code readability and maintainability reasons it was neglected.
Use REPEAT or WHILE instead.

If numeric case is not implemented, use IF ELSIF or IF OR instead

Or look into this “elegant” alternative 😊

 
  IMPORT In, Out, Strings;

 …

  In.Char(ch);

  WHILE In.Done DO

    Strings.Search(ch, “AEIOUaeiou”, pos); IF pos >= 0 THEN INC(countVowels) END;

    In.Char(ch)

  END;

 
The Module Strings.Mod is quite portable.

I can send you the Oberon-07 version of it if you don’t have it.

 
br

Jörg

 

Von: Oberon <oberon-bounces at lists.inf.ethz.ch> im Auftrag von Joe Turner <medianjoe at mailfence.com>
Antworten an: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
Datum: Montag, 24. Januar 2022 um 15:15
An: <oberon at lists.inf.ethz.ch>
Betreff: [Oberon] How to write this program in Oberon-07?

 

I'm working through the book "Into the Realm of Oberon" which is written for Oberon-2. I can't figure out how to translate the following program into Oberon-07 (I'm using the OBNC compiler):

 

MODULE case;

IMPORT In,Out;

 

VAR countVowels: INTEGER; ch: CHAR;

 

BEGIN

  In.Open;

  countVowels:=0;

  LOOP

    In.Char(ch);

    IF ~In.Done THEN EXIT END;

    CASE ch OF

      "a", "e", "i", "o", "u",

      "A", "E","I","O","U": INC(countVowels)

    ELSE

    END;

  END;

  Out.Int(countVowels,0);

  Out.String(" vowels read.");Out.Ln;

END case.

 

Oberon-07 doesn't allow LOOP, EXIT, or ELSE in CASE. 

Thanks in advance for any help.

-- Sent with https://mailfence.com Secure and private email -- Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon 

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

-- Sent with https://mailfence.com  Secure and private email
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20220124/e91dad63/attachment.html>


More information about the Oberon mailing list