Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Using a class level domain in the interface

Unread post by Martin Meyer »

Hello Thomas,

I am not sure whether it is already known or maybe intended. In an interface the compiler (build 802) does not see domains which are declared in the class having the same name as the interface:

Code: Select all

interface someObj   predicates     somePredicate : (someObj::classDomain). %throws Unknown domain/interface 'someObj::classDomain'   end interface someObj   %---   class someObj : someObj   domains     classDomain = unsigned.   end class someObj   %---   implement someObj   clauses     somePredicate(Val) :-         stdIO::write(Val).   end implement someObj
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: Using a class level domain in the interface

Unread post by Thomas Linder Puls »

It is intended.

The reason is that your interface must be valid without "knowing about the class" (whereas the other way around is impossible, because it says class xxx : xxx).

If the interface was not independent of the class you can have strange behavior in places where only the interface is visible (such situation will only happen with a "strange" and unadwisable project structure, but nevertheless ...).
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: Using a class level domain in the interface

Unread post by Martin Meyer »

Thank you for the info!

I have tried to find an example of a project structure in which the strange behavior would show up. But I have no idea what it could be. Can you give a clue?
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: Using a class level domain in the interface

Unread post by Thomas Linder Puls »

It will/can happen if you define the interface in one package and the class in another.

This is both possible and legal, but not something I can recommend. If you do so you will definitely confuse some mechanisms in the IDE, especially the automatic insertion of include directives.

A reason that could incline you to make such a structure is when you consider the interface to be of global interest, but consider the class itself to be a "private" matter. For example the class is only intended to be the base class of a number of different implementations of the interface. This is a good cause, but a bad solution. A better structure for this case would be to use a different name for the base class, e.g. <something>Base.
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: Using a class level domain in the interface

Unread post by Martin Meyer »

I have tested the unadwisable project structure. In below the class domain someObj::classDomain is not visible when the code of interface and class is placed in different packages:

Code: Select all

%%%%%% % This code is in package someInterface   interface someObj   domains     objDomain = unsigned.   end interface someObj   % End of code in package someInterface %%%%%%   %---   %%%%%% % That code is in package someClass   class someObj : someObj   domains     classDomain = unsigned.   end class someObj   implement someObj end implement someObj   % End of code in package someClass %%%%%%   %===   implement main   class predicates     takeObjDomain : (someObj::objDomain). clauses     takeObjDomain(_).   class predicates     takeClassDomain : (someObj::classDomain). %gives unknown domain/interface 'someObj::classDomain' clauses     takeClassDomain(_).   clauses     run() :-         takeObjDomain(1),         takeClassDomain(2).   end implement main
But the above compiles when doing it the adwisable way, placing the code of someObj in a single package.

An alternative idea, to deal with the problem, would be, to let the compiler always see the class level domains, but to prevent creating the unadwisable project structure in the IDE. Of course that is a naive suggestion, because I do not know about all the complex internal details of compiler and IDE.
Regards Martin
Post Reply