Hello,
Before starting, I would like to warn that what I want to do is maybe the bad way to do it :)
I have the following problem :
Several categories implement the same protocol that states that they should declare a predicate with one or zero answer.
An object imports these categories, and want to call, for each one, the predicate and make sure that it succeeds.
I am looking for idea to implement this.
The reason behind this is that I have my Gorgias (see the Porting forum :) that is extended with categories, and I need them to implement a way to verify the consistency of set of terms.
Each category has its own way of checking, but all must succeed for the set to be consistent.
I tried to do his by making categories implement the negation of consistency check, and the object was verifying that none succeeded with findall, but it is problematic since I am committing some constraints in these predicates and want them to stay committed but they are not since the predicate must fail.
If someone has an idea, I will be happy :)
Thanks you,
Victor
Checking that all definitions of a predicate succeed
Moderator: Paulo Moura
-
- Posts: 48
- Joined: Tue May 15, 2007 4:53 pm
-
- Logtalk developer
- Posts: 488
- Joined: Sat May 05, 2007 8:35 am
- Location: Portugal
- Contact:
Re: Checking that all definitions of a predicate succeed
From your description, I assume you're defining aliases in the object in order to access the predicate definition in each category (since the definition in the first imported category will override the definitions in the remaining categories). Is my interpretation correct?Victor NOEL wrote: I have the following problem :
Several categories implement the same protocol that states that they should declare a predicate with one or zero answer.
An object imports these categories, and want to call, for each one, the predicate and make sure that it succeeds.
I am looking for idea to implement this.
So, why not simple define an object predicate that calls all the aliases for the category consistency predicates? The object predicate could use the same name of the consistency predicate as defined in your protocol.Victor NOEL wrote: The reason behind this is that I have my Gorgias (see the Porting forumthat is extended with categories, and I need them to implement a way to verify the consistency of set of terms.
Each category has its own way of checking, but all must succeed for the set to be consistent.
I don't understand why you need to use the negation of the consistency check. Maybe some sample code would help?Victor NOEL wrote: I tried to do his by making categories implement the negation of consistency check, and the object was verifying that none succeeded with findall, but it is problematic since I am committing some constraints in these predicates and want them to stay committed but they are not since the predicate must fail.
Cheers,
Paulo
Paulo Moura
Logtalk developer
Logtalk developer
-
- Posts: 48
- Joined: Tue May 15, 2007 4:53 pm
Re: Checking that all definitions of a predicate succeed
Yes, exactly, I made a little example to show what I want to do, it is hard to explain with words.Paulo Moura wrote: From your description, I assume you're defining aliases in the object in order to access the predicate definition in each category (since the definition in the first imported category will override the definitions in the remaining categories). Is my interpretation correct?
Code: Select all
:- object(obj, imports(two, three)).
:-alias(two, pred/1, pred2/1).
:-alias(three, pred/1, pred3/1).
pred(A) :- pred2(A).
pred(A) :- pred3(A).
test(A) :- % should call pred to be sure that A is true for pred2 and pred3
:- end_object.
:-category(two).
pred(A) :- 0 is A mod 2.
:-end_category.
:-category(three).
pred(A) :- 0 is A mod 3.
:-end_category.
Yes, this can be a good idea. I didn't think about it, the only problem there could be (and maybe it is not a problem in fact) is that I generate the alias and the predicates that call them automatically with hooks.Paulo Moura wrote: So, why not simple define an object predicate that calls all the aliases for the category consistency predicates? The object predicate could use the same name of the consistency predicate as defined in your protocol.
But I don't see why I couldn't generate such a predicate calling all of them.
It is funny because while writing the example, it become clear that it was a good idea :]
It was an idea to do what I want.Paulo Moura wrote: I don't understand why you need to use the negation of the consistency check. Maybe some sample code would help?
I could call :
findall(test, the_contrary_predicate, []).
And be sure that none of them was true. But there was another problem, so I think what you proposed me is the way to go :]
Thanks you for your help
-
- Logtalk developer
- Posts: 488
- Joined: Sat May 05, 2007 8:35 am
- Location: Portugal
- Contact:
Re: Checking that all definitions of a predicate succeed
So it seems that you just need to collect the predicate aliases and convert them into a conjunction that will be called by an object predicate with the same name as the original consistency check predicate.Victor NOEL wrote: Yes, this can be a good idea. I didn't think about it, the only problem there could be (and maybe it is not a problem in fact) is that I generate the alias and the predicates that call them automatically with hooks.
Cheers,
Paulo
Paulo Moura
Logtalk developer
Logtalk developer
-
- Posts: 48
- Joined: Tue May 15, 2007 4:53 pm
Re: Checking that all definitions of a predicate succeed
This is what I did an it worked well :]
Thanks you for the idea !
Victor
Thanks you for the idea !
Victor
Who is online
Users browsing this forum: No registered users and 0 guests