0
votes

I'm trying to understand what happens on this particular situation about Prolog DCG rules. The rules are:

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).

And got:

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

I just cant find the the correct "phrase" to run this grammar. What mistake am I making?

1
How could I miss this? Tanks again.RRBaldi

1 Answers

2
votes

you have a simple typo: try phrase(fizz_buzz(Msg),Codes), and you'll get

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