And from this also debuggers etc.. can be built. Including
solvers that return a kind of proof tree as your proof/2
suggests. And much more.
But it wont be very efficient since a call to clause/2 is
usually slower than a native clause invokation, although
clause/2 might also offer multi-argument indexing. Here is
a little test whether it has multi-argument indexing:
:- dynamic r/2.
r(a, b).
r(a, c).
r(d, c).
r(d, e).
In SWI-Prolog (6.3.4) and Jekejeke Prolog (0.9.6) we have:
?- clause(r(X, c),true).
X = a ;
X = d
?-
So it detects determinism, since after showing the solution
X = d it directly returns to the top level as it didn't find
more choice points. In GNU Prolog (1.4.1) on the other hand
we have:
?- clause(r(X,c),true).
X = a ? ;
X = d ? ;
no
?- (X=a;X=d).
X = a ? ;
X = d
yes
With multi-argument indexing in clause/2 determinism can also
transpire through the last rule of solve/1 and make solve/1
behave as the original program concerning determinism.
The clause/2 system predicate is for example documented here:
Graham Cooper <grahamcoop...@gmail.com> writes:
> On Nov 19, 9:30 am, Alan Smaill <sma...@SPAMinf.ed.ac.uk> wrote:
>> Graham Cooper <grahamcoop...@gmail.com> writes:
>> > Imagine if you could cut down on all the PROLOG RULES
>> > f(a,b,c) :- g(a,b) , h(b,c).
>> > and just use SINGLE FACTS!
>> > if( g(a,b)&h(b,c) , f(a,b,c)).
>> > This would greatly simplify tracing the program run and give you more
>> > control over the facts and implications you manipulate!
>> ever heard of clause/2 from the Prolog standard?
> It looks like it traces the subgoals being invoked.
No, it doesn't;
it gives what you were talking about,
a unit clause corresponding to each normal Prolog program clause.
> Graham Cooper <grahamcoop...@gmail.com> writes:
> > On Nov 19, 9:30 am, Alan Smaill <sma...@SPAMinf.ed.ac.uk> wrote:
> >> Graham Cooper <grahamcoop...@gmail.com> writes:
> >> > Imagine if you could cut down on all the PROLOG RULES
> >> > f(a,b,c) :- g(a,b) , h(b,c).
> >> > and just use SINGLE FACTS!
> >> > if( g(a,b)&h(b,c) , f(a,b,c)).
> >> > This would greatly simplify tracing the program run and give you more
> >> > control over the facts and implications you manipulate!
> >> ever heard of clause/2 from the Prolog standard?
> > It looks like it traces the subgoals being invoked.
> No, it doesn't;
> it gives what you were talking about,
> a unit clause corresponding to each normal Prolog program clause.
but it still uses the UNIFY process to resolve the body/tail.
RULE: HEAD .......... BODY
................less(X,Z) :- less(X,Y), less(Y,Z).
clause( less(X,Z) , less(X,Y),less(Y,Z) ).
----------
FORMAL SYSTEM EMULATING RULES (with 1 or 2 tail segments in body)
if(L,R). // 1 tail segment emulated
rule( N , E, W ). // 2 tail segments emulated
rule( less(X,Z) , less(X,Y) , less(Y,Z) ).
----------
FORMAL SYSTEM 2 and only 2 RULES
t(R) :- if(L,R), t(L).
t(N) :- if(N,E,W), t(E), t(W)
---------
Now you have full control how the predicates are solved and the trace
is extremely simple.