Meta interpreter tracing

Description

A Prolog meta-interpreter for tracing programs

Source: PROLOG programming for artificial intelligence, 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7.

Download

Program source code: meta_interpreter_tracing.pl

Listing

%  Figure 23.2  A Prolog meta-interpreter for tracing programs
%  in pure Prolog.
 
 
% trace( Goal): execute Prolog goal Goal displaying trace information
 
trace( Goal)  :-
  trace( Goal, 0).
 
trace( true, Depth)  :-  !.                      % Red cut; Dept = depth of call
 
trace( ( Goal1, Goal2), Depth)  :-  !,           % Red cut
  trace( Goal1, Depth), 
  trace( Goal2, Depth).
 
trace( Goal, Depth)  :-
  display( 'Call: ', Goal, Depth),
  clause( Goal, Body),
  Depth1 is Depth + 1,
  trace( Body, Depth1),
  display( 'Exit: ', Goal, Depth),
  display_redo( Goal, Depth).
 
trace( Goal, Depth)  :-                          % All alternatives exhausted
  display( 'Fail: ', Goal, Depth),
  fail.
 
display( Message, Goal, Depth)  :-
  tab( Depth), write( Message),
  write( Goal), nl.
 
display_redo( Goal, Depth)  :-
  true                                           % First succeed simply
  ;
  display( 'Redo: ', Goal, Depth),               % Then announce backtracking
  fail.                                          % Force backtracking  

Comments

pl/prolog/pllib/meta_interpreter_tracing.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0