0

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?

repeat
  • 18,496
  • 4
  • 54
  • 166
RRBaldi
  • 11
  • 4

1 Answers1

2

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

?- run.
At fizz we have Msg=_G1212
_G1212
true 
CapelliC
  • 59,646
  • 5
  • 47
  • 90