[Oberon] CASE without ELSE

Jörg joerg.straube at iaeth.ch
Thu Feb 15 18:11:01 CET 2018


We can certainly debate heavily whether there is really a big aesthetical difference:

 

. . . . . . . . . . . 

IF      x=A THEN

                (* statements *)

 

ELSIF x=B THEN

                (* statements *)

 

ELSIF x=C THEN

                (* statements *)

 

END;

. . . . . . . . . . . . 

CASE x OF

   A:

                (* statements *)

| B:

                (* statements *)

| C:

                (* statements *)

END;

. . . . . . 

 

How often did you use CASE in the past?

When you want constant runtime, you could write something like.

 

VAR Statements: ARRAY 10 OF PROCEDURE;

 Statements[x];

 

br

Jörg

 

Von: Oberon <oberon-bounces at lists.inf.ethz.ch> im Auftrag von Diego Sardina <dsar at eml.cc>
Antworten an: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
Datum: Donnerstag, 15. Februar 2018 um 17:59
An: <oberon at lists.inf.ethz.ch>
Betreff: Re: [Oberon] CASE without ELSE

 

On Thu, Feb 15, 2018, at 4:12 PM, Jörg wrote:

 

If you write something like this

  CASE idx OF

    0: idx := idx + 42

  | 2000: idx := idx * 2

  ELSE

  END

and the compiler would implement it with a table, you have 1999 useless entries.

 

In the past Pascal and Modula-2 compilers always limited case labels to 127 or 255,  these two limits

are also reasonable today and the entries' loss is very negligible.

 

 

NW seems to have changed his mind on CASE. The compiler itself rarely uses CASE these days. eg ORS.Get() formerly THE case for CASE uses cascaded IFs

 

 

In "An Oberon Compiler for the ARM Processor", he wrote: The scanner is one of the few routines where a case statement is highly valuable.

 

I agree with that not only for the constant time of the jump table but for the aesthetic, it is a nightmare how it was coded in current PO2013 :-)

 

--

Diego Sardina

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

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


More information about the Oberon mailing list