Discussions related to Visual Prolog
Peter Muraya
VIP Member
Posts: 147
Joined: 5 Dec 2012 7:29

Order of delegation and inheritance: does it matter?

Unread post by Peter Muraya »

Hi all,
Does the order of delegating interfaces to facts matter? And if so, why is it not the case for inheritance? I ask these questions because my program behaved unexpectedly when I used delegation rather than inheritance and I could not figure out a very logical explanation for this.

In the sample below, I have an interface, called fruit, that supports two other interfaces, male and female, which in turn supports a third interface, sex. I have implemented the fruit interface using 3 different ways:

(1) By delegation, where the compiler reports no errors (except for the warning that male and female facts are not used)

(2) By inheritance, and the compile returns a very helpful message: An ambiguous inheritance of the predicate or property definition sex::name (i)' in the class 'fruit' (from classes 'male' and 'female')

(3) By inheritance using the error message in 2 to help me make a rational decision about how a fruit should behave.

Code: Select all

interface sex properties     name:string. end interface   class sex:sex end class   implement sex facts      name:string:=class_name(). end implement /********************************************/   interface male supports sex end interface male   class male:male end class   implement male inherits sex end implement   /********************************************/   interface female supports sex end interface   class female:female end class   implement female inherits sex end implement   /********************************************/   interface fruit supports male, female constants     version:integer = 2. end interface   class fruit:fruit end class   #if fruit::version=1 #then      implement fruit           facts                male:male:=erroneous.                female:female:=erroneous.             delegate interface male to male           delegate interface female to female      end implement fruit #endif   #if fruit::version=2 #then      implement fruit inherits male, female      end implement fruit #endif   #if fruit::version=3 #then      implement fruit inherits male, female           resolve interface sex from male      end implement fruit #endif   /********************************************/   goal     succeed().
Mutall Data Management Technical Support
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

There is clearly a problem here. And I am afraid that I don't have a good answer.

It is not the intention that the order should matter: Version 1 should also give an error. And you would then have to be explicit about the ambiguity:

Code: Select all

    delegate         interface male to male,         interface female to female,         interface sex to male
But if you write like that you will get an error.

We will of course look into this, but that will not help you now.
Regards Thomas Linder Puls
PDC
Peter Muraya
VIP Member
Posts: 147
Joined: 5 Dec 2012 7:29

Order of delegation and inheritance: does it matter?

Unread post by Peter Muraya »

Thanks Thomas.
Ok, so the order matters, and on further investigation, I have seen that it is first-delegation-comes-first. I can live with the problem, until it is fixed, but is there some sort of guarantee that this order always stay them same?
Mutall Data Management Technical Support
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

The compiler you have will do things in a certain way, and the next will do it in the right way :-).
Regards Thomas Linder Puls
PDC
Peter Muraya
VIP Member
Posts: 147
Joined: 5 Dec 2012 7:29

Order of delegation and inheritance: does it matter?

Unread post by Peter Muraya »

The message is clear: no guarantee. Thanks.
Mutall Data Management Technical Support
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

This fixed in build 7502.
Regards Thomas Linder Puls
PDC
Post Reply