您好我是新來的序言和我試圖創建一個基本的家譜,這樣太不公平了我有這樣的:序言未捕獲的異常錯誤
/* Database for family. It consists of facts and rules. */
/* Facts */
female(ella).
female(jodi).
female(sonya).
male(arnold).
male(chris).
male(louis).
male(mark).
father_of(arnold, chris). /* arnold is the father of chris */
father_of(louis, mark).
father_of(mark, arnold).
mother_of(ella, sonya).
mother_of(jodi, ella).
mother_of(jodi, mark).
/* Rules */
grandmother_of(X, Z) :-
mother_of(X, Y),
(mother_of(Y, Z); father_of(Y, Z)).
familyquestions :-
grandmother_of(X, arnold),
write('The grandmother of Arnold is '), write(X), nl,
father_of(Y, mark),
write(Y), write(' is the father of Mark'), nl, nl.
不過,我試圖做到這一點: 定義(添加到數據庫中)如果X是某人的父親,則返回「是」(或「真」)的規則稱爲is_male(X)。
請注意,如果系統找到「真實」答案並且不存在更多真實答案,系統將返回「是」。系統將返回「真實?」如果它找到了「真實」的答案,並且還有可能進一步匹配。在 這種情況下,如果你輸入「enter」,它將返回「yes」並停止。如果您輸入「;」,它將繼續搜索更多答案。 1.2定義一個稱爲is_female(X)的規則,如果X是某人的母親,則返回「yes」或「true」。
1.3刪除(註釋掉)已添加到數據庫中的不重要的事實(已被新規則is_male/1和is_female/1覆蓋)。
所以我加了這個
/*家庭數據庫。它由事實和規則組成。 */
/* Facts */
female(ella).
female(jodi).
female(sonya).
male(arnold).
male(chris).
male(louis).
male(mark).
father_of(arnold, chris). /* arnold is the father of chris */
father_of(louis, mark).
father_of(mark, arnold).
mother_of(ella, sonya).
mother_of(jodi, ella).
mother_of(jodi, mark).
/* Rules */
grandmother_of(X, Z) :-
mother_of(X, Y),
(mother_of(Y, Z); father_of(Y, Z)).
is_male(X, Y) :-
father_of(X, Y).
is_female(X, Y) :-
mother_of(X, Y).
familyquestions :-
grandmother_of(X, arnold),
write('The grandmother of Arnold is '), write(X), nl,
father_of(Y, mark),
write(Y), write(' is the father of Mark'), nl, nl.
但是當我運行它,它給了我這樣的代碼: 未捕獲的異常:錯誤(existence_error(程序,is_male/1),TOP_LEVEL/0)
歡迎來到SO!由於您是新手,您可能需要查看此[鏈接](http://meta.stackexchange.com/a/5235/187716)。 – fferri