0
我想確定有人訪問下面的存儲順序,併購買了以下項目:序言 - 試圖確定根據給定的事實商店訪問的順序
商店:
1. kingtoots
2. leftorium
3. sprawlmart
4. trynsave
項目:
1. saxophone
2. dress
3. pacifier
4. slingshot
這裏是給定的事實S:
1. He bought the saxophone book at King Toots
2. The store he visited immediately after buying the slingshot was not Sprawl-Mart
3. The Leftorium was his second stop
4. Two stops after leaving Try-N-Save, he bought the pacifier
編寫基於給定信息的Prolog事實的幾次嘗試後,這裏是我想出了:
purchase(saxophone, king_toots).
purchase(greendress, X).
purchase(pacifier, X).
purchase(slingshot, X).
store(leftorium, X).
store(king_toots, saxophone).
store(sprawlmart, X).
store(trynsave, X).
stop1(X, Y) :- store(X, Y), purchase(Y, X).
stop2(X, Y) :- store(leftorium, X), purchase(X, leftorium).
stop3(X, Y) :- store(X, Y), purchase(Y, X).
stop4(X, Y) :- store(X, Y), purchase(Y, X).
然而,當我在SWI-Prolog的運行它,我得到以下錯誤:「爲什麼我得到這個錯誤」
2 ?- stop2(X, Y).
ERROR: toplevel: Undefined procedure: stop2/2 (DWIM could not correct goal)
這是更多的是「請指導我正確的方向」寫的事實/邏輯,而不是我對Prolog和邏輯編程很陌生,所以在這裏的任何幫助將不勝感激。