URL87
URL87

Reputation: 11012

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

Upvotes: 3

Views: 5961

Answers (2)

Anders Lindahl
Anders Lindahl

Reputation: 42870

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

Upvotes: 3

Theodoros Chatzigiannakis
Theodoros Chatzigiannakis

Reputation: 29213

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.

Upvotes: 1

Related Questions