Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

downloaded swi-prolog, where is the editor?

Status
Not open for further replies.

stjgen

Programmer
Jan 16, 2006
1
SE
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...

what do you use as an IDE?
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top