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

Interface synonyms

Unread post by Martin Meyer »

Hello Thomas,

just a small suggestion regarding interface synonyms, maybe this could be made working in some future version:

Code: Select all

interface obj{@Type}   domains     myType =         myType_a(@Type);         myType_b.   end interface obj   implement main   domains     obj_unsigned = obj{unsigned}.   clauses     run() :-         Val = obj_unsigned::myType_a(1), %throws error c218 : Unknown class/interface 'obj_unsigned'         stdIO::write(Val).   end implement main
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1202
Joined: 28 Feb 2000 0:01

Re: Interface synonyms

Unread post by Thomas Linder Puls »

You can just write:

Code: Select all

implement main   clauses     run() :-         Val = obj::myType_a(1),         stdIO::write(Val).   end implement main
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 286
Joined: 14 Nov 2002 0:01

Re: Interface synonyms

Unread post by Martin Meyer »

True, that makes the example's code even shorter. In large use cases however things can be the other way around. I.e. when declarations made in an interface obj{@TypeA, @TypeB, ...} are refered to many times in the code and in each place type parameters are substituted by same lengthy type expressions.

Merry Christmas to you and all
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1202
Joined: 28 Feb 2000 0:01

Re: Interface synonyms

Unread post by Thomas Linder Puls »

An interface defines an object type, and as such it defines the predicates and properties that such objects have.

For convenience an interface is however also a scope that can declare constants and domains, but these constants and domains belongs to the scope not to the interface type (and they are not accessible through the objects).

So an interface definition is a single textural construction that defines two things, an object type and a static/global scope.

We have no intensions about extending object types to carry more than the predicates and properties of the corresponding objects.

Likewise we have no intensions about extending an synonym type to do more than defining a synonym of a type.

So the definition

Code: Select all

domains     obj_unsigned = obj{unsigned}.
Defines a synonym of the type, but it is not the type that contains the myType domain, so you cannot write:

Code: Select all

obj_unsigned::myType
But you can define this synonym type (i.e. because is it a type):

Code: Select all

domains     myType_unsigned = obj{unsigned}::myType.
You may also be able to handle things by opening obj{unsigned}.
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 286
Joined: 14 Nov 2002 0:01

Re: Interface synonyms

Unread post by Martin Meyer »

Thank you for the detailed explanation. Now I see the concept behind scenes.

I suppose the issue is connected to Supports Qualification for Domains. Similarly a supports qualification extends the type of an interface but not its scope.
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1202
Joined: 28 Feb 2000 0:01

Re: Interface synonyms

Unread post by Thomas Linder Puls »

Martin Meyer wrote: 19 Dec 2017 15:09Similarly a supports qualification extends the type of an interface but not its scope.
Exactly.
Regards Thomas Linder Puls
PDC
Post Reply