Вопрос

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

Это было полезно?

Решение

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

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top