This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/metainterpreters/metainterpreters.lgt
pmoura 3455276aa2 Logtalk 2.26.2 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1487 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2005-12-24 18:07:41 +00:00

89 lines
1.8 KiB
Plaintext

:- object(solver).
:- info([
version is 1.0,
date is 2004/5/2,
author is 'Paulo Moura',
comment is 'Simple meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
:- public(solve/1).
:- mode(solve(+goal), zero_or_more).
:- info(solve/1, [
comment is 'Proves goal.',
argnames is ['Goal']]).
solve(true) :-
!.
solve((A, B)) :-
!, solve(A), solve(B).
solve(A) :-
clause(A, B), solve(B).
:- end_object.
:- object(proof_tree).
:- info([
version is 1.0,
date is 2004/5/2,
author is 'Paulo Moura',
comment is 'Meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
:- public(solve/2).
:- mode(solve(+goal, -tree), zero_or_more).
:- info(solve/2, [
comment is 'Constructs a proof tree for a goal.',
argnames is ['Goal', 'Tree']]).
solve(true, true).
solve((A, B), (PA, PB)) :-
!, solve(A, PA), solve(B, PB).
solve(A, (A :- PB)) :-
clause(A, B), solve(B, PB).
:- end_object.
:- object(tracer).
:- info([
version is 1.0,
date is 2004/5/5,
author is 'Paulo Moura',
comment is 'A simple tracer meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
:- public(trace/1).
:- mode(trace(+goal), zero_or_more).
:- info(trace/1, [
comment is 'Traces goal proof.',
argnames is ['Goal']]).
trace(Goal) :-
trace(Goal, 1).
trace(true, _) :-
!.
trace((A, B), Depth) :-
!, trace(A, Depth), trace(B, Depth).
trace(A, Depth) :-
write_trace(call, A, Depth),
clause(A, B),
Depth2 is Depth + 1,
trace(B, Depth2),
( write_trace(exit, A, Depth)
;
write_trace(redo, A, Depth),
fail).
trace(A, Depth) :-
write_trace(fail, A, Depth),
fail.
write_trace(Port, Goal, Depth) :-
write(Depth), write(' '), write(Port), write(': '), writeq(Goal), nl.
:- end_object.