Re: how to make this fail driven loop succesfull ?

Bob Minors <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Roelof,

You can make your failure-drive loop finish as 'true' like this:

siblings(Father,Mother) :- is_father(X, Father), is_mother(X, Mother), write(X), nl, fail ; true.

Reading from left-to-right, when it has found all the possible values
for X and failed to find any more with backtracking, it will try the
right-hand branch of the ';' and finally succeed with the 'true'.


On 08/03/2014 21:00, Roelof Wobben wrote:
> Hello, 
>
>
> I have these facts: 
>
>
> male(roelof). 
>
> male(mans).
>
> male(jan).
>
>
> female(chantal). 
>
> female(tamara). 
>
> female(marie).
>
> female(gerda). 
>
>
> parent(roelof,tamara).
>
> parent(mans, roelof). 
>
> parent(jan, chantal). 
>
> parent(marie, roelof). 
>
> parent(chantal, tamara).
>
> parent(mans, gerda).
>
> parent(marie, gerda). 
>
>
> is_mother(Child,Mother):- 
>
> parent(Mother, Child),
>
> female(Mother).
>
>
>
> is_father(Child, Father):- 
>
> parent(Father, Child),
>
> male(Father). 
>
>
>
> siblings(Father,Mother) :- 
>
> is_father(X, Father), 
>
> is_mother(X, Mother),
>
>  write(X),
>
>  nl, 
>
> fail.
>
>
> When I do siblings(mans,marie) it produces:
>
>
> roelof
>
> gerda
>
> no
>
>
> How can I change this to make the output like this:
>
>
> roelof
>
> gerda
>
> yes. 
>
>
> I have tried to add siblings(_) but with no success 
>
>
> Roelof 		 	   		  
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.