INTERACTING WITH THE PROLOG SYSTEM Marcus V. Santos 1- Loading/exiting Prolog ---------------------- To invoke the XSB-Prolog just enter the following command on the UNIX prompt: xsb You will notice that the following message will be printed on the screen: XSB Version 1.7.1 [Solaris, optimal mode] | ?- The symbol "| ?-" is the Prolog prompt. From now on, Prolog will try to prove any well-formed expression you type in followed by a dot, ".", and E.g.: | ?- a. Undefined predicate/function: a/0 Aborting... | ?- This is an error, since no predicate "a" has been previously defined. To exit Prolog just type: | ?- halt. 2- To load files containing Prolog programs ---------------------------------------- Editing and loading programs in Prolog is very similar to the way you do it in Scheme. Basically you have to edit your file (using any text editor) in the same directory you are running Prolog. Suppose you already invoked Prolog, and you also edited and saved your program under the file name "test.P". You can load it into the Prolog knowledge base using the following command: | ?- [test]. Don't forget that after the dot (".") you have to press . Each time you modify your program and want to test it, first turn off any trace predicated that happen to be turned on, then load your program. Section 3 introduces what you have to do to trace programs. 3- There is another way to input predicates. At the Prolog prompt type: -------------------------------------------------------------------- | ?- [user]. [Compiling user] You will notice that Prolog will wait for more inputs. Then just type the Prolog rules (facts) that you would like to test. Don't forget that each rule or fact must be followed by "." E.g.: father(tom, eric). father(eric, alan). father(joan, eric). To quit this input mode, just type Ctrl-D. And Prolog will resume loading your predicates. The following message will be presented thereafter: [user compiled, cpu time used: 0.5810 seconds] [user loaded] yes | ?- 4- Tracing your program -------------------- (Note: this section presents just the essentials of tracing programs. More information can be obtained from: http://www.cs.sunysb.edu/~sbprolog/manual/manual.html Look inside the link "debugging" end-Note) To turn on tracing, just type | ?- trace. To turn tracing off, type: | ?- notrace. When tracing is on, the system will print a message each time a predicate is: 1.initially entered (Call), 2.successfully returned from (Exit), 3.failed back into (Redo), and 4.completely failed out of (Fail). At each port, a message is printed and the tracer stops and prompts for input. In addition to single-step tracing, the user can set spy points to influence how the tracing/debugging works. A spy point is set using spy/1. Spy points can be used to cause the system to enter the tracer when a particular predicate is entered. Also the tracer allows ``leaping'' from spy point to spy point during the debugging process. When the tracer prompts for input, the user may enter a return, or a single character followed by a return, with the following meanings: c, : Creep Causes the system to single-step to the next port (i.e. either the entry to a traced predicate called by the executed clause, or the success or failure exit from that clause). a: Abort Causes execution to abort and control to return to the top level interpreter. b: Break Calls the evaluable predicate break, thus invoking recursively a new incarnation of the system interpreter. The command prompt at break level n is n: ?- The user may return to the previous break level by entering the system end-of-file character (e.g. ctrl-D), or typing in the atom end_of_file; or to the top level interpreter by typing in abort. f: Fail Causes execution to fail, thus transferring control to the Fail port of the current execution. h: Help Displays the table of debugging options. l: Leap Causes the system to resume running the program, only stopping when a spy-point is reached or the program terminates. This allows the user to follow the execution at a higher level than exhaustive tracing. 5- Last, but not least: how to interrupt an endless loop ----------------------------------------------------- If your program happen to enter an endless loop, just type: Ctr-c