root/trunk/examples/metainterpreters/metainterpreters.lgt

Revision 4601, 2.1 KB (checked in by pmoura, 7 weeks ago)

Added svn:mime-type property to source files (set to text/x-logtalk).

  • Property svn:mime-type set to text/x-logtalk
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- category(solver).
3
4    :- info([
5        version is 1.1,
6        date is 2008/10/2,
7        author is 'Paulo Moura',
8        comment is 'Simple meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
9
10    :- public(solve/1).
11    :- mode(solve(+goal), zero_or_more).
12    :- info(solve/1, [
13        comment is 'Proves goal.',
14        argnames is ['Goal']]).
15
16    solve(true) :-
17        !.
18    solve((A, B)) :-
19        !,
20        solve(A),
21        solve(B).
22    solve(A) :-
23        clause(A, B),   % retrieves clauses in "this", i.e. in the database of the object importing the category
24        solve(B).
25
26:- end_category.
27
28
29:- category(proof_tree).
30
31    :- info([
32        version is 1.1,
33        date is 2008/10/2,
34        author is 'Paulo Moura',
35        comment is 'Meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
36
37    :- public(proof_tree/2).
38    :- mode(proof_tree(+goal, -tree), zero_or_more).
39    :- info(proof_tree/2, [
40        comment is 'Constructs a proof tree for a goal.',
41        argnames is ['Goal', 'Tree']]).
42
43    proof_tree(true, true) :-
44        !.
45    proof_tree((A, B), (PA, PB)) :-
46        !,
47        proof_tree(A, PA),
48        proof_tree(B, PB).
49    proof_tree(A, (A :- PB)) :-
50        clause(A, B),   % retrieves clauses in "this", i.e. in the database of the object importing the category
51        proof_tree(B, PB).
52
53:- end_category.
54
55
56:- category(tracer).
57
58    :- info([
59        version is 1.1,
60        date is 2008/10/2,
61        author is 'Paulo Moura',
62        comment is 'A simple tracer meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
63
64    :- public(trace/1).
65    :- mode(trace(+goal), zero_or_more).
66    :- info(trace/1, [
67        comment is 'Traces goal proof.',
68        argnames is ['Goal']]).
69
70    trace(Goal) :-
71        trace(Goal, 1).
72
73    trace(true, _) :-
74        !.
75    trace((A, B), Depth) :-
76        !,
77        trace(A, Depth),
78        trace(B, Depth).
79    trace(A, Depth) :-
80        write_trace(call, A, Depth),
81        clause(A, B),   % retrieves clauses in "this", i.e. in the database of the object importing the category
82        Depth2 is Depth + 1,
83        trace(B, Depth2),
84        (   write_trace(exit, A, Depth)
85        ;   write_trace(redo, A, Depth),
86            fail
87        ).
88    trace(A, Depth) :-
89        write_trace(fail, A, Depth),
90        fail.
91
92    write_trace(Port, Goal, Depth) :-
93        write(Depth), write(' '), write(Port), write(': '), writeq(Goal), nl.
94
95:- end_category.
Note: See TracBrowser for help on using the browser.