Checking that all definitions of a predicate succeed

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Checking that all definitions of a predicate succeed

Post by Victor NOEL » Mon Jul 14, 2008 3:23 pm

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

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

Re: Checking that all definitions of a predicate succeed

Post by Paulo Moura » Mon Jul 14, 2008 7:14 pm

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.
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: 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.
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: 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.
I don't understand why you need to use the negation of the consistency check. Maybe some sample code would help?

Cheers,

Paulo
Paulo Moura
Logtalk developer

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Checking that all definitions of a predicate succeed

Post by Victor NOEL » Tue Jul 15, 2008 9:06 am

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?
Yes, exactly, I made a little example to show what I want to do, it is hard to explain with words.

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.
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.
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.

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 :]
Paulo Moura wrote: I don't understand why you need to use the negation of the consistency check. Maybe some sample code would help?
It was an idea to do what I want.
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

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

Re: Checking that all definitions of a predicate succeed

Post by Paulo Moura » Tue Jul 15, 2008 11:53 am

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.
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.

Cheers,

Paulo
Paulo Moura
Logtalk developer

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Checking that all definitions of a predicate succeed

Post by Victor NOEL » Tue Jul 15, 2008 12:36 pm

This is what I did an it worked well :]

Thanks you for the idea !

Victor

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest