i downloaded swi-prolog but there doesnt seem to be an editor, just a top-level like in lisp. i can get up some sort of editor but there is no run or compile function in it, just seems like a normal texteditor...
i'm a newbie too but i think that emacs. is the editor ...
Starting EMACS
We are going to use EMACS to edit our sources, so start the EMACS editor by typing "emacs." at the SWI-PROLOG prompt. It is very important that you don't forget the final dot (each PROLOG statement must end with a dot). If everything goes fine, the EMACS editor should load. Now, switch to PROLOG mode by choosing File / Mode / Prolog. You should see something like this:
This is where you are going to edit your PROLOG sources. You can get the same effect by typing "emacs('source.pl')." at the PROLOG prompt. This will load the file source.pl into the EMACS editor and automatically switch to PROLOG mode because of the .pl extension, which is implicit for PROLOG sources. For now, you can type the following lines:
parent(john,thomas).
parent(andrew,michael).
parent(jack,daniel).
Save the file using File / Save As, or File / Save Buffer if your file already has a name.
Compiling And Posing The First Query
You are now ready to compile your PROLOG source. Choose Compile / Compile Buffer or press CTRL-c followed by CTRL-b. Now go to the SWI-PROLOG window. Some messages must have appeared, confirming that compilation was successful. Everything is ready for you to pose queries, so don't make SWI-PROLOG wait and ask who is Andrew's parent. You can do that by typing: "parent(andrew , X).". Again, you shouldn't forget the final dot. SWI-PROLOG will answer that Andrew's parent is Michael. Please, note that X is capitalized. If you don't capitalize it, you won't get the expected answer.
Congratulations! You have just made your first steps with PROLOG.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.