Search code examples
prologprolog-toplevel

ERROR: Undefined procedure: (:-)/2


I'm new in Prolog , I am trying to set rule on SWI-Prolog shell e.g -

listensToMusic(X) :- happy(X).

But it prompts -

ERROR: Undefined procedure: (:-)/2

I use SWI-Prolog version 6.2.6


Solution

  • SWI-Prolog does not accept new rules and facts on the top-level, it only accepts queries.

    Rules are typically added by writing them in a text file (for example rules.pl), and load it into SWI-Prolog using:

    ?- [rules].
    

    Absolute paths to files can be used like this:

    ?- ['C:/Program Files/pl/demo/likes'].
    

    You can type rules by issuing [user]., typing your rule and ending with EOF (typically Ctrl-D):

    ?- [user].
    |: listensToMusic(X) :- happy(X).
    |: <EOF> 
    true.
    

    There is an elaborate FAQ on this subject: ERROR: Undefined procedure: (:-)/1 | (:-)/2 | (?-)/1