Tracer

Description

A tracer for Prolog

Source: The Art of Prolog

Download

Program source code: tracer.pl

Listing

/*  
  solve_trace(Goal) :-
	Goal is true given the pure Prolog program defined by 
	clause/2. The program traces the proof by side effects.
*/
 
solve_trace(Goal) :-
	solve_trace(Goal,0).
 
     solve_trace(true,Depth) :- !.
     solve_trace((A,B),Depth) :-  !,
        solve_trace(A,Depth), solve_trace(B,Depth). 
     solve_trace(A,Depth) :-  
	builtin(A), !, A, display(A,Depth), nl.
     solve_trace(A,Depth) :-
        clause(A,B), 
	display(A,Depth), nl,
	Depth1 is Depth + 1, 
	solve_trace(B,Depth1).
 
     display(A,Depth) :-  Spacing is 3*Depth, put_spaces(Spacing), write(A). 
 
     	put_spaces(N) :- between(1,N,I), put_char(' '), fail.
	put_spaces(N).
 
     between(I,J,I) :- I =< J.
     between(I,J,K) :- I < J, I1 is I + 1, between(I1,J,K).
 
%	Program 17.7	A tracer for Prolog

Comments

pl/prolog/pllib/tracer.txt · ostatnio zmienione: 2017/07/17 08:08 (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