[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
PrologDebug
Typical predicates used are:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
PrologDebug
(Prolog) Debug, to debug, debugging
Debugging is the process of removing runtime errors. This process can be aided by a debugger.Typical predicates used are:
Example
The code below has a simulated error. Using a good debugger with the function 'Trace into' you can see that the call to doIt(5) checks doIt(1), doIt(2) and then ends at doIt(_).
PREDICATES
nondeterm doIt(integer)
CLAUSES
doIt(1) :-
write("1"), nl,
doit(5).
doIt(2) :-
write("2"), nl.
doIt(3) :-
write("3"), nl.
doIt(4) :-
write("4"), nl.
doIt(_) :-
write("ERROR"), nl.
GOAL
doIt(1).
Debugging function
% The clause 'trace' is a debugging function:
% * trace(integer DebugLevel, string Debugmessage)- (i,i)
% * DebugLevel: only when below a certain value,
% the DebugMessage will be stored
% * DebugMessage: The message that will be appended to the file
% 'Trace.txt'
global domains
FILE = myDebugFile
predicates
trace(integer,String)- (i,i)
clauses
trace(DebugLevel,DebugMessage) IF
DebugLevel < 50, % 50 is set as the default debug level
openappend(myDebugFile,"Trace.txt"),
writedevice(myDebugFile),
write(DebugMessage),
write("\n"),
writedevice(stdout),
closefile(myDebugFile),
!.
trace(_,_) IF
% No problem, DebugLevel is too high
!.
goal
trace(1,"I am written to file."),
trace(100,"I am not written to file.").
'Debug' links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
