Information Technology Reference
In-Depth Information
In these cases, the execution can be interrupted by typing a Control-C (holding
down the Ctrl key and typing a C ). Prolog then displays the following and waits for
a character to be typed:
Action (h for help) ?
There are a number of options here (typing a ? will show them), but the main two are
as follows:
c (for continue) tells Prolog to continue as if it had not been interrupted;
a (for abort) tells Prolog to give up on the entire query.
Of course, aborting a query like this is a desperation measure, but sometimes it is the
only way to regain control and go on to try something else. Almost certainly some
tracing will be needed to find out what went wrong.
C.3 Saving a record of program execution
Once a program is finally behaving the way it should, the only thing left to do is to
make a record of the way it responds to queries. The simplest way to do this is to use
the special predicates protocol and noprotocol . Here is the idea:
?- protocol('myfile.txt').
Yes
Some queries are now entered and their responses are produced.
?- noprotocol.
Yes
The result of this is that a text file called myfile.txt is created in the same folder as
the Prolog program. All the queries and their responses between the protocol and
noprotocol will be saved to this file. (The text file will also contain a spurious first
and last line, but these are easy to remove.)
As a final note, it is sometimes useful to use the protocol feature of SWI-Prolog to
deal with a very long trace. By sending the trace to a file, it can be examined later,
parts can be edited out, and the trace can be printed.
 
 
Search WWH ::




Custom Search