Let's consider the following example:
MODULE test;
IMPORT Out;
TYPE
Animal = RECORD END;
Cat = RECORD (Animal) END;
Dog = RECORD (Animal) END;
VAR
x: Cat;
y: Dog;
PROCEDURE P(VAR x: Animal);
BEGIN
CASE x OF
Animal: Out.String("animal"); Out.Ln
| Cat: Out.String("cat"); Out.Ln
| Dog: Out.String("dog"); Out.Ln
END
END P;
BEGIN
P(x);
P(y)
END test.
What should be the output from this module?
Regards,
August
On Thu, 7 Sep 2017 13:04:17 +0200, August Karlstrom
<fusionfile@gmail.com> wrote:
Let's consider the following example:
MODULE test;
IMPORT Out;
TYPE
Animal = RECORD END;
Cat = RECORD (Animal) END;
Dog = RECORD (Animal) END;
VAR
x: Cat;
y: Dog;
PROCEDURE P(VAR x: Animal);
BEGIN
CASE x OF
Animal: Out.String("animal"); Out.Ln
| Cat: Out.String("cat"); Out.Ln
| Dog: Out.String("dog"); Out.Ln
END
END P;
BEGIN
P(x);
P(y)
END test.
What should be the output from this module?
Regards,
August
Since the intent of the CASE statement here is to distinguish the
subclass of an Animal instance (and not the value of the Animal
instance), it shouldl fail to compile. Using the Oberon-2 WITH
statement to perform type testing (in the style of a CASE statement)
is one way to get around this.
Regards,
Lance
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 293 |
Nodes: | 16 (2 / 14) |
Uptime: | 234:49:43 |
Calls: | 6,624 |
Files: | 12,172 |
Messages: | 5,319,700 |