?? family.pl
字號(hào):
female(ann).
female(cathy).
female(lisa).
female(lora).
female(mary).
female(rose).
female(susan).
male(charles).
male(david).
male(fred).
male(george).
male(ian).
male(joe).
male(john).
male(paul).
male(peter).
mother_of(john,ann).
mother_of(mary,ann).
mother_of(cathy,ann).
mother_of(peter,mary).
mother_of(paul,mary).
mother_of(charles,cathy).
mother_of(susan,cathy).
mother_of(george,lora).
mother_of(ian,lora).
mother_of(lisa,rose).
father_of(john,fred).
father_of(mary,fred).
father_of(cathy,fred).
father_of(peter,joe).
father_of(paul,joe).
father_of(charles,david).
father_of(susan,david).
father_of(george,paul).
father_of(ian,paul).
father_of(lisa,charles).
parents(Child,Mother,Father) :-
mother_of(Child,Mother),
father_of(Child,Father).
sisters(X,Y) :- female(X), female(Y),
X \= Y,
parents(X,M,F),
parents(Y,M,F).
is_grandfather(G) :- father_of(X,G),
(mother_of(_,X); father_of(_,X)).
ancestor_of(P,A) :- mother_of(P,A).
ancestor_of(P,A) :- father_of(P,A).
ancestor_of(P,A) :- mother_of(P,M), ancestor_of(M,A).
ancestor_of(P,A) :- father_of(P,M), ancestor_of(M,A).
ancestors_of(P,As) :- bagof(A,ancestor_of(P,A),As).
descendants_of(P,Ds) :- bagof(D,ancestor_of(D,P),Ds).
is_grandmother(G) :- mother_of(X,G),
(mother_of(_,X); father_of(_,X)).
% inferior implementation of grandparents/0 returning multiple instances ...
% grandparents :- (is_grandmother(G);is_grandfather(G)), write(G), nl, fail.
% grandparents.
grandparents :- setof(G,(is_grandmother(G); is_grandfather(G)),Gs),
writelist(Gs).
writelist([]).
writelist([H|T]) :- write(H), write(', '), writelist(T).
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -