[Oberon] CASE without ELSE
joerg.straube at iaeth.ch
Thu Feb 15 16:12:03 CET 2018
You’re right. A time ago, I detected this as well.
I guess it’s on purpose.
The compiler doesn’t even implement the numeric case. Only CASE for type extension is implemented; NW neglected WITH.
The case statement performs the same function as the if statement. However, it is intended to use a different technique of implementation, namely a single, indexed branch instead of a cascade of conditional branches. This is sensible only if the cases are distinguished by a (mostly) contiguous range of label values.
If you write something like this
CASE idx OF
0: idx := idx + 42
| 2000: idx := idx * 2
and the compiler would implement it with a table, you have 1999 useless entries.
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
Von: Oberon <oberon-bounces at lists.inf.ethz.ch> im Auftrag von Josef Templ <josef.templ at gmail.com>
Antworten an: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
Datum: Donnerstag, 15. Februar 2018 um 15:28
An: <oberon at lists.inf.ethz.ch>
Betreff: [Oberon] CASE without ELSE
recently I noticed that there is no ELSE clause in the CASE statement of the latest Oberon language version.
Has this been removed intentionally or accidentally? Or is there something new instead of it?
If it has been removed intentionally:
Is there a significant simplification in the compiler or a speedup at runtime?
On the other side, it puts some burden onto the programmer to work around it.
As an example: I tried to implement a simple command interpreter that reads a character
from a serial line (connected to a keyboard) and executes a related procedure in an embedded target.
The natural language construct, I thought, would be a CASE for that kind of problem.
Pressing an invalid key could be ignored easily by the ELSE clause of the CASE.
-- 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...
More information about the Oberon