Question

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

Was it helpful?

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

OTHER TIPS

My Prolog skills are dusty at best, but as far as I remember you are supposed to declare things in a file, then consult the file to load it into the workspace and then use the shell to ask questions about the workspace. To declare something in the shell would require an assertion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top