Re: what wrong with this setof

Roelof Wobben <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
 
> Date: Sun, 16 Mar 2014 23:13:55 +1300
> Subject: Re: [SWIPL] what wrong with this setof
> From: [email protected]
> To: [email protected]
> 
> > Hello,
> >
> > I changed my clause to this :
> >
> > display_siblings(X,Y) :-
> >      setof(X-Y, (siblings(X,Y), \+X=Y), Sibs),
> >                member((X-Y,Y), Sibs),
> >                \+ (Y@<X, member((Y,X), Sibs)).
> 
> (1) People are not siblings of themselves.
>     If your definition of siblings/2 allows this, it is wrong.
>     If it doesn't, the \+(X=Y) test is pointless.
>     Probable state: you need X\==Y inside siblings/2 and NOT here.
> 
> (2) findall/3, bagof/3, and setof/3 agree that the third
>     argument will be bound to a list of instances (filled-in
>     copies) of the first argument.  So when setof/3 succeeds,
>     each member of Sibs is a pair X-Y where X and Y are
>     presumably names of people.  This means that
>     member((X-Y,Y), Sibs) cannot possibly find anything that
>     looks like (X-Y,Y).  Similarly, member((Y,X), Sibs)
>     cannot possibly succeed because the elements of Sibs
>     look like (X-Y) *not* like (X,Y).
> 
Thanks, 
I m playing with the way setof does the output.  According to another member of this list I could do this :  > You can make pairs by using any two-place functor such as the popular -/2:
> 
> ?- setof(X-Y, parents(X, Y), Parents).
> Parents = [adam-eve, alice-bob, harry-sally]. 
  		 	   		  
-------------- next part --------------
HTML attachment scrubbed and removed
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.