문제

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