Specifying and enforcing type constraints on object predicates?

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Locked
JacquesRobin
Posts: 3
Joined: Sat May 23, 2020 8:01 am

Specifying and enforcing type constraints on object predicates?

Post by JacquesRobin »

Hi,

As a Logtalk newb, I am wondering whether there is way in Logtalk to specify and then enforce type constraints on Logtalk class predicates/features/roles. For example, I may want to specify that the clauses that define the child predicate of any object instantiating the class person are defined in such a way that a query P::child(C) where P is instantiated by an object of the class person, can only return as values for C objects of the class person. Once I specify this constraint I would also want an error to be generated if I try to instantiate an object of the class person with a clause defining the predicate child with a bound argument that is not an instance of person.

This is straightforwardly expressed in the UML, imperative object-oriented programming languages and OWL/Description Logics ontologies. Perhaps the built-in predicates of the hierarchy library provide the building blocks to specify and enforce such constraints. However, given that when creating a new object O of a class C one can always add new clauses providing additional alternative definitions for a given predicate, I am unsure how to specify and enforce a specific type constraint for the argument of a predicate of an object.

Thanks in advance for any idea/insight on this question.

Paulo Moura
Logtalk developer
Posts: 533
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Specifying and enforcing type constraints on object predicates?

Post by Paulo Moura »

The library "type" object provides building blocks for type-checking predicate arguments:

https://logtalk.org/manuals/libraries/types.html
https://logtalk.org/library/type_0.html

Another option, using the type-checking predicates mentioned above, is to use the events and monitors to watch for messages/predicates that you want to type-check:

https://logtalk.org/manuals/userman/events.html

P.S. Don't forget to reply to my followup questions on the previous thread you started here.
Paulo Moura
Logtalk developer

Locked