作者okara (PS)
看板Examination
標題[考題] 程式語言考古題
時間Wed Jun 24 17:13:58 2015
◎高考三級/資訊處理/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的結果是對的,那執行步驟為何?
感謝回答。
============================================
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.163.171.166
※ 文章網址: https://www.ptt.cc/bbs/Examination/M.1435137241.A.D94.html
→ emstarbucks: 補習班錯了 06/25 00:57
推 emstarbucks: 還有公X王網路上那的答案也是錯的 06/25 01:25
→ APE36: 補習班的答案錯 06/25 19:28