我试图了解有关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 :(得分:2)
你有一个简单的拼写错误:尝试phrase(fizz_buzz(Msg),Codes),
,你就会得到
?- run.
At fizz we have Msg=_G1212
_G1212
true