[Oberon] CASE without ELSE
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Thu Feb 15 19:43:17 CET 2018
> Hi everybody,
>
> 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?
>
> ...
>
> - Josef
Josef,
1. The numeric case, i.e. where the type T of the case expression (case variable) is of type INTEGER or CHAR, is not actually implemented in Oberon 2013. As a consequence, one now needs to use e.g. an IF statement instead.
2. Only the case where the type T of the case expression (case variable) is a RECORD or POINTER type is implemented in Oberon 2013. In this case, the case labels must be extensions of T. This is typically used in installed handler procedures in the Oberon viewer system - which now seems to have become the intended main use of CASE.
Now one can why there is no ELSE clause: If the type T of the case expression is a RECORD or POINTER type, the ELSE can always be simulated by simply specifying the *base* type of T as the *last* element in the case list.
.. as in MenuViewers.Handle:
CASE M OF
Oberon.InputMsg: ... |
Oberon.ControlMsg: ... |
Oberon.CopyMsg: ... |
Display.FrameMsg: .. (*this is in fact the ELSE clause*)
END
One just needs to get the order right: extended types first, base type last (if one placed the base type at the beginning of the list, it would always evaluate to TRUE even if M were an extension of T)
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20180215/b336e16b/attachment.html>
More information about the Oberon
mailing list