2014-05-11 80 views
0

我想了解在關於Prolog DCG規則的這種特殊情況下會發生什麼。規則是:Prolog DCG短語錯誤

fizz_buzz(Msg) --> anything, fizz(Msg), anything, buzz, anything. 

anything --> []. 
anything --> [_], anything. 

fizz(Msg) --> 
    "fizz", 
    { 
     format('At fizz we have Msg=~w~n', [Msg]) 
    }. 

buzz --> 
    "buzz". 

run :- 
    atom_codes("blah blah fizz blah buzz", Codes), 
    phrase(fiz_buzz(Msg), Codes), 
    write(Msg). 

,並得到:

ERROR: phrase/3: Undefined procedure: fiz_buzz/3 
ERROR: However, there are definitions for: 
ERROR:   fizz_buzz/3 

我只是無法找到正確的「這句話」來運行該語法。 我犯了什麼錯誤?

+0

我怎麼能錯過呢?坦克再次。 – RRBaldi

回答

2

你有一個簡單的拼寫錯誤:試圖phrase(fizz_buzz(Msg),Codes),,你會得到

?- run. 
At fizz we have Msg=_G1212 
_G1212 
true