« Return to Thread: Forall in SWI Prolog

Re: Forall in SWI Prolog

by Paulo Moura :: Rate this Message:

Reply to Author | View in Thread


On 2009/07/04, at 17:48, Fatih TURKMEN wrote:

>
> Dear All,
>
> I am running into a problem with forall predicate of SWI-Prolog. I  
> have the following predicate that tries to match all  
> subjectMatch(....) with rSub(...). This makes sure all different  
> combinations of subjectMatch(...) facts with different RID and  
> RValue values are matched. However, forall returns True when the  
> Condition section of forall predicate is not matched. That means if  
> there is no fact matching the condition of forall (that is  
> subjectMatch(P,R,N,RID,RValue)) forall returns True as a default  
> value.
>
> subjectS(P,R,N)  :-  forall(subjectMatch(P,R,N,RID,RValue),
>              rSub(RID,RValue)).
>
> Is there a way to get around this? I mean if the condition of forall  
> is not matched at all, how can I get a false?


subjectS(P, R, N) :-
        \+ \+ subjectMatch(P, R, N, _, _),
        forall(subjectMatch(P, R, N, RID, RValue), rSub(RID, RValue)).

Cheers,

Paulo


-----------------------------------------------------------------
Paulo Jorge Lopes de Moura, PhD
Assistant Professor
Dep. of Computer Science, University of Beira Interior
6201-001 Covilhã, Portugal

Office 3.18  Ext. 3276
Phone: +351 275319891 Fax: +351 275319899
Email: <mailto:pmoura@...>

Home page: <http://www.di.ubi.pt/~pmoura>
Research:  <http://logtalk.org/> Blog: <http://blog.logtalk.org/>
-----------------------------------------------------------------

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

 « Return to Thread: Forall in SWI Prolog