2015-04-27 52 views
1

我有一個關於我得到的錯誤的快速問題。我是prolog新手,所以請原諒,如果它是一個簡單的修復。Prolog併發症錯誤

這裏是我正在試圖做的事:

Consider the database created in question 1. In implementing the following rules, you can add additional rules to make your implementation easier.


2.1 Add the following set of rules that extend the family relations among the members: (1) parent_of, (2) sibling_of, (3) uncle_of, (4) uncleOrAunt_of, (5) spouse_of, and (6) descendant_of


2.2 Add at least 10 facts into the database. These new facts should show consistent relationship among family members and must ensure (1) no conflict facts,(2) no redundant information, (3) each rule defined in question 2.1 can return a "yes" value for at least one set of parameters.


2.4 Add a rule called fullQuestions at the end of database to test all the rules that you have defined in the homework. Include sufficient write statements, so that the answers to individual questions are printed. Make sure that the compound question can terminate (will not cause a "dead loop"). Include the output as comments.

這是我走到這一步:

/* 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(X,Y) :- 
    parent_of(X,Y), is_male(X). 
father_of(arnold, chris). /* arnold is the father of chris */ 
father_of(louis, mark). 
father_of(mark, arnold). 

mother_of(X,Y) :- 
    parent_of(X,Y), is_female(X). 
mother_of(ella, sonya). 
mother_of(jodi, mark). 

child(X, Y) :- 
    parent_of(Y, X). 

parent_of(X, Y) :- 
    child(Y, X). 

parent_of(jodi, ella). 
parent_of(jodi, mark). 
parent_of(louis, mark). 
parent_of(mark, arnold). 
parent_of(jose, sergio). 
parent_of(ana, sergio). 
parent_of(jose, gio). 
parent_of(ana, gio). 
parent_of(joe, jose). 
parent_of(mary, jose). 

/* Rules */ 


grandmother_of(X, Z) :- 
      mother_of(X, Y), 
      (mother_of(Y, Z); father_of(Y, Z)). 

is_male(X) :- 
    father_of(X, _). 
is_female(X) :- 
    mother_of(X, _). 

sibling_of(X, Y) :- 
parent_of(Z, X), parent_of(Z, Y). 

sister(X,Y) :- 
    siblings(X,Y), is_female(X), X \= Y. 

brother(X,Y) :- 
    siblings(X,Y), is_male(X), X \= Y. 

uncle_of(X,Y) :- 
brother(X,Z), mother_of(Z,Y). 
uncle_of(X,Y) :- 
brother(X,Z), father_of(Z,Y). 

uncleOrAunt_of(X, Y) :- 
    brother(X,Z), mother_of(Z,Y). 
uncleorAunt_of(X, Y) :- 
    brother(X,Z), father_of(Z,Y). 
uncleorAunt_of(X, Y) :- 
    sister(X,Z), father_of(Z,Y). 
uncleorAunt_of(X, Y) :- 
    sister(X,Z), mother_of(Z,Y). 

spouse_of(X,Y) :- 
    child(P, X), child(P, Y). 

ancestor(X , Y) :- 
    parent_of(X , Y). 
ancestor(X , Y) :- 
    parent_of(X , Z) , ancestor(Z , Y). 

descendant_of(X, Y) :- 
    ancestor(Y, X). 

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. 

然而,當我嘗試編譯它,我得到多個錯誤:

/tmp/gplcExLkpg.o:在功能`謂詞(姐姐/ 2)「:

(+的.text 0x7b3 ):未定義參考`謂詞(兄弟姐妹/ 2) '

/tmp/gplcExLkpg.o:在功能`謂詞(兄弟/ 2)':

(的.text + 0x843):未定義參考`謂語(同胞/ 2)'

collect2:錯誤:LD返回1個退出狀態

編譯失敗

+0

您在'parent_of(mary,jose),'中有一個錯字。它應該以點而不是逗號結束。 – gusbro

+0

好的,謝謝!我修好了,但現在我有兩個不同的erros? –

+0

family.pl:64-65:warning:不連續謂詞parent_of/2 - 子句忽略 family.pl:75:致命錯誤:重新定義控件構造(',')/ 2 編譯失敗 –

回答

1

的 「警告:不連續的謂詞parent_of/2 - 條款忽略錯誤」 啪啪因爲在parent_of/2謂詞的分離。 嘗試parent_of(X, Y) :- child(Y, X).權下parent_of(mary, jose).

這樣的:

father_of(X,Y) :- parent_of(X,Y), is_male(X). 
father_of(arnold, chris). /* arnold is the father of chris */ 
father_of(louis, mark). 
father_of(mark, arnold). 

mother_of(X,Y) :- parent_of(X,Y), is_female(X). 
mother_of(ella, sonya). 
mother_of(jodi, mark). 

parent_of(X, Y) :- child(Y, X). 
parent_of(jodi, ella). 
parent_of(jodi, mark). 
parent_of(louis, mark). 
parent_of(mark, arnold). 
parent_of(jose, sergio). 
parent_of(ana, sergio). 
parent_of(jose, gio). 
parent_of(ana, gio). 
parent_of(joe, jose). 
parent_of(mary, jose). 

等。

我不記得確切的語法,但幾乎可以肯定的 「;」 (或)應該工作:

uncleOrAunt_of(X, Y) :- 
    (brother(X,Z), mother(Z,Y)); 
    (brother(X,Z), father(Z,Y)); 
    (sister(X,Z), father(Z,Y)); 
    (sister(X,Z), mother(Z,Y)). 

試試看,讓我知道。 任何方式這一點,你可以修復致命的錯誤與重寫

uncleOrAunt_of(X, Y) :-brother(X,Z), mother(Z,Y). 
uncleOrAunt_of(X, Y) :-brother(X,Z), father(Z,Y). 
uncleOrAunt_of(X, Y) :-sister(X,Z), father(Z,Y). 
uncleOrAunt_of(X, Y) :-sister(X,Z), mother(Z,Y). 

希望使事情清晰,即時通訊的權利。

.............................................. ......

+0

他男人謝謝,但是在我之後做了更改,我得到了幾個不同的錯誤 –

+0

沒有致命的錯誤了。你是否試圖對謂詞進行分組? – yeg

+0

你是什麼意思分組? –