程式語言考古題 - 高考

Table of Contents


◎高考三級/資訊處理/102年 第五題

考慮下述Prolog程式:
ancestor(x,x).
ancestor(x,y) :- ancestor(z,y), parent(x,z).
parent(Allen, John).
用一個subgoal的搜尋樹(search tree),描述此Prolog程式在執行查詢:
ancestor(Allen,X)時的執行步驟。

Ans:

(高上的解答是)

ancestor(Allen,X) → ancestor(Allen, Allen) {X = Allen} failure
→ ancestor(Allen, John) {X = John}
→ancestor(Z, John), parent(Allen, Z) {Z = John}
→ancestor(John, John) {Z = John} success
→ancestor(Allen, John) {Z = John} success


(實際用prolog得到的結果是)

1 ?- ancestor(Allen,X).
Allen = X, X = x

============================================

請問版上高手,哪個才是對的。
又如果prolog的結果是對的,那執行步驟為何?

感謝回答。

============================================

--

All Comments

Damian avatarDamian2015-06-28
補習班錯了
Eden avatarEden2015-07-01
還有公X王網路上那的答案也是錯的
Olive avatarOlive2015-07-05
補習班的答案錯