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/SCRIPT
pmoura 75b2645e3f Logtalk 2.27.1 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1580 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2006-03-26 17:31:34 +00:00

114 lines
2.1 KiB
Plaintext

=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.27.1
Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
=================================================================
% start by loading the example:
| ?- logtalk_load(metainterpreters(loader)).
...
% solver - a simple meta-interpreter for pure Prolog:
| ?- solver::assertz(member_of(H, [H| _])).
H = _G178
yes
| ?- solver::assertz((member_of(H, [_| T]) :- member_of(H, T))).
H = _G181
T = _G179
yes
| ?- solver::solve(member_of(2, [1,2,3])).
yes
| ?- solver::solve(member_of(X, [1,2,3])).
X = 1 ;
X = 2 ;
X = 3
yes
% proof_tree - a simple meta-interpreter for pure Prolog that
% construct a proof tree:
| ?- proof_tree::assertz(member_of(H, [H| _])).
H = _G178
yes
| ?- proof_tree::assertz((member_of(H, [_| T]) :- member_of(H, T))).
H = _G181
T = _G179
yes
| ?- proof_tree::solve(member_of(2, [1,2,3]), Tree).
Tree = member_of(2, [1, 2, 3]):- (member_of(2, [2, 3]):-true)
yes
% tracer - a simple meta-interpreter for tracing goal proofs
% using pure Prolog:
| ?- tracer::assertz(member_of(H, [H| _])).
H = _G178
yes
| ?- tracer::assertz((member_of(H, [_| T]) :- member_of(H, T))).
H = _G181
T = _G179
yes
| ?- tracer::trace(member_of(3, [1,2,3])).
1 call: member_of(3, [1, 2, 3])
2 call: member_of(3, [2, 3])
3 call: member_of(3, [3])
3 exit: member_of(3, [3])
2 exit: member_of(3, [2, 3])
1 exit: member_of(3, [1, 2, 3])
yes
| ?- tracer::trace(member_of(X, [1,2,3])).
1 call: member_of(_G187, [1, 2, 3])
1 exit: member_of(1, [1, 2, 3])
X = 1 ;
1 redo: member_of(1, [1, 2, 3])
2 call: member_of(_G187, [2, 3])
2 exit: member_of(2, [2, 3])
1 exit: member_of(2, [1, 2, 3])
X = 2 ;
1 redo: member_of(2, [1, 2, 3])
2 redo: member_of(2, [2, 3])
3 call: member_of(_G187, [3])
3 exit: member_of(3, [3])
2 exit: member_of(3, [2, 3])
1 exit: member_of(3, [1, 2, 3])
X = 3 ;
1 redo: member_of(3, [1, 2, 3])
2 redo: member_of(3, [2, 3])
3 redo: member_of(3, [3])
4 call: member_of(_G187, [])
4 fail: member_of(_G187, [])
3 fail: member_of(_G187, [3])
2 fail: member_of(_G187, [2, 3])
1 fail: member_of(_G187, [1, 2, 3])
no