Re: how to refractor this ?
Feliks Kluzniak <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hi, It strikes me that you don’t need the variables in the head of „display_brother( X, Y )” etc.: in fact, they seem quite useless. To answer your question: you could use call/n. Something along the following lines: display_relation( Relation ) :- setof( X - Y, (call( Relation, X, Y ), X @< Y), Set ), write( Set ). which would then be called, e.g., by … display_relation( siblings ), … Please note that I haven’t tested this code. Hope this helps, — Feliks On Mar 18, 2014, at 17:07, Roelof Wobben <[email protected]> wrote: > I have this piece: > > siblings(Child, Sibling) :- > same_father(Child, Sibling), > Child \= Sibling. > siblings(Child, Sibling) :- > same_mother(Child, Sibling), > Child \= Sibling. > > display_siblings(X,Y):- > setof(X-Y, (siblings(X,Y), X @< Y), Sibs), > write(Sibs). > > brother_child(Child, Brother) :- > siblings(Child, Brother), > male(Brother). > > display_brother(X,Y) :- > setof(X-Y, (brother_child(X,Y), X @< Y),Brother), > write(Brother). > > sister_child(Child, Sister) :- > siblings(Child, Sister), > female(Sister). > > display_sister(X,Y) :- > setof(X-Y, (sister_child(X,Y), X @< Y),Sister), > write(Sister). > > As you can see the display are almost the same except the calling rule and the name of the variable. > > Is there a way I can make one big display function. > and can I refractor more here ? > > Roelof > > > -------------- next part -------------- > HTML attachment scrubbed and removed > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog