On Friday, December 29, 2017 at 1:23:22 PM UTC+10:30, Lance Schwerdfager wrote:
On Thu, 7 Sep 2017 13:04:17 +0200, August Karlstrom
<[email protected]> 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
I disagree. The CASE statement above is legal as it stands. WITH in Oberon-2 behaves exactly the same as CASE in Oberon-07.
WITH
x: Cat DO Out.String("cat"); Out.Ln
| x: Dog DO Out.String("dog"); Out.Ln
| x: Animal DO Out.String("animal"); Out.Ln
END
gives the output
cat
dog
whereas
WITH
x: Animal DO Out.String("animal"); Out.Ln
| x: Cat DO Out.String("cat"); Out.Ln
| x: Dog DO Out.String("dog"); Out.Ln
END
gives the output:
animal
animal
Regards,
Chris Burrows
CFB Software
http://www.astrobe.com
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)