我在Prolog寫了一個族譜程序。這裏是我的規則:序言「沒有足夠的堆棧」錯誤
father(X,Y):-male(X),parent(X,Y).
mother(X,Y):-female(X),parent(X,Y).
parent(X, Y) :- father(X, Y).
parent(X, Y) :- mother(X, Y).
ancestor(X,Y):-parent(X,Y).
ancestor(X,Y):-parent(X,Z),ancestor(Z,Y).
grandfather(X,Y):-male(X),parent(X,Z),parent(Z,Y).
grandMother(X,Y):-female(X),parent(X,Z),parent(Z,Y).
sibling(X,Y):-parent(Z,X),parent(Z,Y),X \= Y.
cousin(X,Y) :-ancestor(Z,X),ancestor(Z,Y),not(parent(Z,X)),not(parent(Z,X)),not(ancestor(X,Y)),not(ancestor(Y,X)).
但是,每當我查詢「祖先」我得到的錯誤:
1815KB of Code Space (025D0000--02795D90)
Current hole: 4FE40000--80040000
%
% PC: user:parent/2 at clause 1
% Continuation: prolog:$do_yes_no/2 at clause 2
% 512KB of Global Stack (029C2000--02A4207C)
% 1265384KB of Local Stack (02A55E4C--4FE10000)
% 0KB of Trail (4FE10004--4FE10044)
% Performed 1 garbage collections
% All Active Calls and
% Goals With Alternatives Open (Global In Use--Local In Use)
%
% user:parent/2 (512KB--1265384KB)
% user:parent/2 (512KB--1265384KB)...
% ...user:parent/2 (512KB--1265377KB)
% .....
ERROR!!
RESOURCE ERROR- not enough stack
這也導致問題的「表哥」的規則,這給
%
%
% YAP OOOPS: likely bug in YAP, segmentation violation.
%
%
我可以用我的「祖先」規則做錯了什麼?
那麼在「父/ 2」和「父/ 2」之間有一個無限循環例如... –