[Oberon] Oberon-07, recursion and type extension

Darren Bane dbane at SDF-EU.ORG
Thu Jul 28 00:04:38 CEST 2016


Thanks, that's perfect. Once I understood the problem, it was no problem. 
It reminds me of another caveat, that "CASE" doesn't work for INTEGERs 
yet. I have no problem with either decision, Oberon-07 is still a very 
useful programming language, it just might be nice to have them 
highlighted more.


On Wed, 27 Jul 2016, Paul Reed wrote:

> Date: Wed, 27 Jul 2016 22:26:51 +0100
> From: Paul Reed <paulreed at paddedcell.com>
> To: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
> Subject: Re: [Oberon] Oberon-07, recursion and type extension
> 
> Hi Darren,
>
>> I always get "incompatible parameters" errors at the recursive calls to
>> [Write]()....
>>    PROCEDURE Write(o: Parent);
>>    BEGIN CASE o OF
>>        Son: Write(o.wife) |
>>        Daughter: Write(o.husband)
>>      END
>>    END Write;
>
> You've come across a nasty implementation issue - if you use CASE to
> temporarily change the type of a parameter, it will temporarily change the
> definition of the procedure too; so the recursive calls are expecting Son
> and Daughter in each branch respectively.  I think the old WITH suffered
> from the same problem.
>
> Just in the case of recursive calls, you might want to stick with the old
> pattern
>
>   IF o IS Son THEN
>     Write(o(Son).wife)
>   ELSIF o IS Daughter THEN
>     Write(o(Daughter).husband)
>   END
>
> or alternatively, assign the pointer o to a local variable of type Parent
> and then change that with a CASE.
>
> HTH
> Paul
>
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>

dbane at sdfeu.org
SDF-EU Public Access UNIX System - http://sdfeu.org


More information about the Oberon mailing list