Page 1 of 1

Using a class level domain in the interface

Posted: 24 Jan 2019 0:15
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

Re: Using a class level domain in the interface

Posted: 24 Jan 2019 15:20
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 ...).

Re: Using a class level domain in the interface

Posted: 24 Jan 2019 18:07
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?

Re: Using a class level domain in the interface

Posted: 24 Jan 2019 21:52
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.

Re: Using a class level domain in the interface

Posted: 29 Jan 2019 10:28
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.