[Oberon] Oberon-07, recursion and type extension

Paul Reed paulreed at paddedcell.com
Wed Jul 27 23:26:51 CEST 2016


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




More information about the Oberon mailing list