I just want to create something like: like(x,y)
.
I've been trying for a long time and am really frustrated, could anyone please tell me how to do it???!!!
问题:
回答1:
I'm assuming you are using swi interactively and trying to enter the fact gives you an error like so:
1 ?- like(x, y).
ERROR: toplevel: Undefined procedure: like/2 (DWIM could not correct goal)
Since the fact does not exist in the database. If this is the case, try asserting the fact first:
2 ?- assert(like(x,y)).
true.
Then you can try:
3 ?- like(x, y).
true.
This time the query succeeds because the fact exists in the database.
A better approach might be to write your clauses into a file & then consult them. Swi prolog has an emacs-like editor that you can bring up by typing
emacs.
at the prompt. Or use your own editor & then consult the file. Swi prolog comes with a lot of graphical tools that might be of help; look at the manual for more details.
回答2:
You can create facts a prolog file and load them using consult function.
For example,
animals.pl
bigger(elephant, tiger).
bigger(tiger, rabbit).
bigger(rabbit, sparrow).
bigger(sparrow, ant).
You can also use assert function to define facts in prolog terminal.
1 ?- assert(bigger(elephant, rabbit)).
true.
Refer this link, to get more infromation.