2013-03-26 71 views
2

我正在參加初級prolog課程。我們應該使用SWI-序言,這裏就是我的說未定義的過程s/1謂詞

% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 3,856 bytes 
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.10.4) 

我們要求開發算術謂詞加(X,Y,Z)。使用後繼的(X)[= X + 1]函數。此謂詞在我的機器上出現以下錯誤:

ERROR: toplevel: Undefined procedure: s/1 (DWIM could not correct goal) 

有沒有人有解決方案?我必須降級我的swipl,也許?

謝謝!

回答

2

你的SWI-Prolog很好,但你誤解了這個任務。您必須使用Peano表示法編寫add/3的定義,而不是通常的數字,例如2代表s(s(0))。您可以搜索類似的問題,例如I answered,以幫助您理解在您所面對的相同環境下實際的Prolog執行情況。

1

您不必降級解釋的版本,因爲s/1不是一個實際的謂詞(這就是爲什麼你收到此錯誤)。如你所知,s/1只代表「繼承者」,它用於遞歸表示數字。

The natural numbers in Prolog are built from two constructs, the constant symbol 0 and the successor function s of arity 1. All the natural numbers are then recursively given as 0, s(0), s(s(0)), s(s(s(0))), ... . We adopt the convention that sn(0) denotes the integer n, that is, n applications of the successor function to 0

[斯特林L.,Shaphiro E., 「序言的藝術」,第2版。 - 麻省理工學院出版社]

我想你會發現this related question有趣。