這裏,有沒有隨着時間進入。 我想下面的代碼來找出哪些是最後一個條目:得到或給予?在Prolog中查找最後一個條目
got(1).
gave(2).
got(3).
gave(4).
got(5).
gave(6).
got(7).
isLastGot():-
findall(G, Got(G), Lg),
findall(A, Gave(A), La),
Lgg is lastElement(Lg),
Laa is lastElement(La),
Lgg > Laa.
lastElement([H|T],A):-lastElement([T],A).
lastElement([A],A).
但它不工作:
?- isLastGot().
ERROR: functor/3: Domain error: `compound_non_zero_arity' expected, found `isLastGot()'
?- isLastGot.
ERROR: toplevel: Undefined procedure: isLastGot/0 (DWIM could not correct goal)
?-
問題出在哪裏以及如何可以把它糾正?
編輯:如果我用下面,我得到的錯誤上載:
isLastGot:-
findall(G, Got(G), Lg),
findall(A, Gave(A), La),
Lgg is lastElement(Lg),
Laa is lastElement(La),
Lgg > Laa.
錯誤:... /gotgave.pl:11:14:語法錯誤:操作員預計 也有許多的警告作者:got/1的條款不在源文件中 (類似的警告也爲給/ 1)
該文件未加載。
即使把所有的GOT和所有給了一起,雖然警告和錯誤都走了,主運行時錯誤仍然堅持後:
1 ?- isLastGot.
ERROR: toplevel: Undefined procedure: isLastGot/0 (DWIM could not correct goal)
2 ?- isLastGot().
ERROR: functor/3: Domain error: `compound_non_zero_arity' expected, found `isLastGot()'
3 ?-
這是無論我是否使用isLastGot(): - 或isLastGot: - 在聲明中。
'isLastGot()'在Prolog中是無效的語法。嘗試'isLastGot'。在*兩個地方(聲明和呼叫)。 – lurker
即使將其更正爲isLastGot: - 然後嘗試與isLastGot。我得到的錯誤:錯誤:toplevel:未定義的過程:isLastGot/0(DWIM無法更正目標) – rnso
代碼中有許多問題。你顯示'Got(G)'和'Gave(A)'都是大寫的,這是一個錯誤。這些應該是'得到(G)'和'給(A)'。我想我已經提到過幾次,Prolog中的謂詞不是* functions *。他們不像功能。所以'Lgg是lastElement(Lg)'沒有意義。它應該是'lastElement(Lg,Lgg)'。您可能還收到了有關不連續謂詞的警告(交替「got」和「give」)。在一些序言中,不連貫的事實/謂詞將被忽略。 – lurker