How to create a fact in SWI-Prolog?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)