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

Joe Turner medianjoe at mailfence.com
Mon Jan 24 20:04:48 CET 2022


August, thanks for that. Are you by any chance the author of OBNC? Not that I'm an expert - far from it, but it's a very nice compiler and easy to use. 

I never learned OOP with Turbo Pascal and have been avoiding it for a long time because the terminology put me off - classes, methods, polymorphism, inheritance etc. One of the things which attracted me to Oberon is the way OOP is handled; it's just an extension of the record concept, so I'm looking forward to learning it at last. Good to know you experts are on hand to help me out if I get stuck!

Thanks again to you and Jorg for the words of wisdom. 

Joe

January 24, 2022 7:29:53 PM CET August Karlstrom <fusionfile at gmail.com> wrote:As mentioned by Jörg, Oberon-07 is a pure structured language in the 
sense that each (ASSERT free) statement sequence is either fully 
executed or not executed. With CASE statements you can often limit the 
range of values to inspect before the CASE statement is executed. Here 
is one way to do it:

MODULE case;

	IMPORT In, Out;

	VAR
		countVowels: INTEGER;
		ch, capCh: CHAR;

BEGIN
	In.Open;
	countVowels := 0;
	In.Char(ch);
	WHILE In.Done DO
		IF (ch >= "a") & (ch <= "z") THEN
			capCh := CHR(ORD("A") + ORD(ch) - ORD("a"))
		ELSE
			capCh := ch
		END;
		IF (capCh >= "A") & (capCh <= "U") THEN
			CASE capCh OF
				"A", "E","I","O","U":
					INC(countVowels) |
				"B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", 
"R", "S", "T":
					(*do nothing*)
			END
		END;
		In.Char(ch)
	END;
	Out.Int(countVowels, 0);
	Out.String(" vowels read.");
	Out.Ln
END case.

With the WHILE loop we can see instantly that it will continue until 
there are no more characters to read. Compare this to the LOOP in which 
the exit condition (or possibly exit conditions) is buried in the 
contained statement sequence.

-- August

On 2022-01-24 15:14, Joe Turner wrote:
> 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/882ca41f/attachment.html>


More information about the Oberon mailing list