0
我現在這個工作的重複我所想要的:如何避免這種情況下
male(roelof).
male(mans).
male(ronald).
male(jan).
female(chantal).
female(marie).
female(gerda).
female(dagmar).
female(denise).
female(kimberly).
parent(mans,gerda).
parent(mans,roelof).
parent(marie,gerda).
parent(marie,roelof).
parent(dagmar,denise).
parent(dagmar,kimberly).
parent(ronald,denise).
parent(ronald,kimberly).
parent(chantal,tamara).
parent(roelof,tamara).
parent(jan,chantal).
parent(jan,dagmar).
% Looks for the father of a child. Gives the name if found.
% if no father is found then it gives false
father_child(Child) :-
parent(Father, Child),
male(Father).
% Looks for the mother of a child. Gives the name if found.
% if no mother is found then it gives false
mother_child(Child) :-
parent(Mother, Child),
female(Mother).
% Looks if two person has the same father.
% Gives true if a person is a father of both persons
% Gives false if no person is a father of both persons.
same_father(Child, Sibling) :-
parent(Father,Child),
parent(Father,Sibling),
male(Father).
% Looks if two person has the same mother.
% Gives true if a person is a mother of both persons
% Gives false if no person is a mother of both persons.
same_mother(Child, Sibling) :-
parent(Mother,Child),
parent(Mother,Sibling),
female(Mother).
% Looks if there are siblings of a person.
% Persons are siblings if they have the same father or
% if they have the same mother and not the same father.
siblings(X,Y) :-
( same_father(X, Y),
X \= Y
; same_mother(X, Y),
\+ same_father(X, Y)
).
% Displays the output of siblings(X,Y) and takes care that
% there are no duplicates.
display_siblings(Person) :-
findall(Person - Y, (siblings(Person,Y), Y @< Person), Sibs),
display_the_siblings(Sibs).
% Display a message if there are no siblings found.
display_the_siblings([]) :-
write('Er zijn geen zussen/broers bekend').
display_many([]).
display_many([H|T]):-
writeln('Many elements '-H), display_many(T).
display_the-siblings([X]):- better_display([X]),!.
display_the_siblings([H|T]):- better_display([H|T]).
better_display([X]):-
writeln('Single Element '-X).
better_display([X,Y|T]):-
writeln('Many elements '-X), display_many([Y|T]).
但在這種情況下display_siblings(金佰利)是假的,因爲kimberly @< denise
失敗。 我是否打開規則以便Y @< Person
然後display_siblings(kimberly)
起作用,但display(gerda)
失敗。
任何想法擺脫這個混亂?
魯洛夫
它是在代碼的一部分。我認爲你必須滾動一點 – user3426797