Changeset 4477 for trunk/examples
- Timestamp:
- 10/02/08 08:42:54 (3 months ago)
- Location:
- trunk/examples/metainterpreters
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/metainterpreters/metainterpreters.lgt
r2800 r4477 3 3 4 4 :- info([ 5 version is 1. 0,6 date is 200 4/5/2,5 version is 1.1, 6 date is 2008/10/2, 7 7 author is 'Paulo Moura', 8 8 comment is 'Simple meta-interpreter for pure Prolog with only conjunctions as clause bodies.']). … … 21 21 solve(B). 22 22 solve(A) :- 23 ::clause(A, B),23 clause(A, B), % retrieves clauses in "this", i.e. in the database of the object importing the category 24 24 solve(B). 25 25 … … 30 30 31 31 :- info([ 32 version is 1. 0,33 date is 200 4/5/2,32 version is 1.1, 33 date is 2008/10/2, 34 34 author is 'Paulo Moura', 35 35 comment is 'Meta-interpreter for pure Prolog with only conjunctions as clause bodies.']). … … 48 48 proof_tree(B, PB). 49 49 proof_tree(A, (A :- PB)) :- 50 ::clause(A, B),50 clause(A, B), % retrieves clauses in "this", i.e. in the database of the object importing the category 51 51 proof_tree(B, PB). 52 52 … … 57 57 58 58 :- info([ 59 version is 1. 0,60 date is 200 4/5/5,59 version is 1.1, 60 date is 2008/10/2, 61 61 author is 'Paulo Moura', 62 62 comment is 'A simple tracer meta-interpreter for pure Prolog with only conjunctions as clause bodies.']). … … 79 79 trace(A, Depth) :- 80 80 write_trace(call, A, Depth), 81 clause(A, B), 81 clause(A, B), % retrieves clauses in "this", i.e. in the database of the object importing the category 82 82 Depth2 is Depth + 1, 83 83 trace(B, Depth2), 84 84 ( write_trace(exit, A, Depth) 85 ;86 write_trace(redo, A, Depth),87 fail).85 ; write_trace(redo, A, Depth), 86 fail 87 ). 88 88 trace(A, Depth) :- 89 89 write_trace(fail, A, Depth), -
trunk/examples/metainterpreters/NOTES.txt
r4466 r4477 28 28 To use a meta-interpreter with an object, simply import the corresponding 29 29 category. 30 31 Defining meta-interpreters as categories allows the use of the built-in 32 predicate clause/2 to access the clauses of object predicates without 33 forcing these predicates to be declared public or protected. Within a 34 category, calls to the built-in predicate clause/2 retrieve clauses in 35 "this", i.e. in the database of the object importing the category. -
trunk/examples/metainterpreters/rules.lgt
r3201 r4477 8 8 9 9 :- op(200, fx, if). 10 :- op(100, xfx, then). 10 :- op(150, xfx, then). 11 :- op(100, xfy, &). 11 12 12 13 prove(true) :- 13 14 !. 14 15 prove([]) :- 16 !. 17 prove([Cond| Conds]) :- 15 prove(Cond & Conds) :- 18 16 !, 19 17 prove(Cond), 20 18 prove(Conds). 21 22 19 prove(Fact) :- 23 ::clause(Fact, true).20 clause(Fact, true). 24 21 prove(Conclusion) :- 25 ::clause(if Conds then Conclusion, true),22 clause(if Conds then Conclusion, true), 26 23 prove(Conds). 27 24 … … 38 35 39 36 :- op(200, fx, if). 40 :- op(100, xfx, then). 37 :- op(150, xfx, then). 38 :- op(100, xfy, &). 41 39 42 if [weather(sunny), weekday(weekend), time(day)]then goto(beach).43 if [weather(raining), weekday(weekend), time(night)]then goto(cinema).44 if [weekday(workday), time(day)]then goto(work).40 if weather(sunny) & weekday(weekend) & time(day) then goto(beach). 41 if weather(raining) & weekday(weekend) & time(night) then goto(cinema). 42 if weekday(workday) & time(day) then goto(work). 45 43 46 44 weather(raining).
