The difference between IF and CASE is, that in the CASE the type of the expression is changed to the type extension. Very handy for message handlers. See below

TYPE
  Base = RECORD END
  Ext = RECORD (Base) i: INTEGER END;
  Ext2 = RECORD (Base) c: CHAR END;

PROCEDURE CaseExample(VAR b: Base);
  BEGIN
    CASE b OF
    Ext:      b.i := 0
    | Ext2: b.c := „A“
    END;
    (* this is equivalent *)
    IF b IS Ext THEN b(Ext).i := 0
    ELSIF b is Ext2 THEN b(Ext2).c := „A“
    END
  END CaseExample;

Jörg

Am 17.02.2018 um 23:32 schrieb Arthur Yefimov <artur.efimov@gmail.com>:

Andreas wrote:​
​> ​
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)

​Does it mean that CASE statement for pointer/record types work like an IF statement? Does it sequentially check all options one by one until it hits the right one? In this case, what does "CASE" give in comparison to using "IS" clause,​ i.e. "IF obj IS MyViewer THEN ... ELSIF obj IS ..."?

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