% consult this in prolog to test your code

:- consult(kinship).
:- consult(myfamily).

% here are the predicates for MW7

hw7predicate(child/2).
hw7predicate(daughter/2).
hw7predicate(parent/2).
hw7predicate(mother/2).
hw7predicate(sibling/2).
hw7predicate(brother/2).
hw7predicate(grandparent/2).
hw7predicate(grandmother/2).
hw7predicate(uncle/2).
hw7predicate(sister_in_law/2).
hw7predicate(mother_in_law/2).
hw7predicate(spouse/2).
hw7predicate(wife/2).
hw7predicate(ancestor/2).
hw7predicate(descendant/2).
hw7predicate(relative_by_blood/2).
hw7predicate(male/1).
hw7predicate(female/1).
% hw7predicate(relative/2).

% the ancient sicstus on gl does not have forall, so we efine a
% similar control predicate forevery

% for every way to satisfy goal G, call P
forevery(G,P) :- G, myonce(P), fail.
forevery(_,_).

% myonce(P) satisfy P just one time
myonce(P) :- P, !.

% the ancient sicstus on gl seems not to have member as a builtin
mymember(X, [X|_Tail]).
mymember(X, [_Head|Tail]) :- mymember(X,Tail).


% test each hw7 predicate
test :- forevery(hw7predicate(P), testPred(P)).

testPred(Pred/1) :-
  % test predicate P by finding and printing the set of all provable instances
  format('~n~w/1:~n', [Pred]),
  Goal =.. [Pred, X],
  setof(X, Goal, Results),
  forevery(mymember(A, Results),
           format('  ~w(~w)~n', [Pred,A])).


testPred(Pred/2) :-
  % test predicate P by finding and printing the set of all provable instances
  format('~n~w/2:~n', [Pred]),
  Goal =.. [Pred, X, Y],
  setof((X,Y), Goal, Results),
  forevery(mymember((X,Y), Results),
           format('  ~w(~w,~w)~n', [Pred,X,Y])).

testPred(_).

:- test.
