Re: Strange clause/2 predicate behaviour in SWI-Prolog
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 25 Mar 2006 09:28:05 GMT
On 2006-03-24, Jose' de Siqueira <jose@xxxxxxxxxxx> wrote:
The following behaviour of clause/2 in SWI-Prolog is very strange, to
say the least:
Welcome to SWI-Prolog (Multi-threaded, Version 5.6.7)
Copyright (c) 1990-2006 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- clause((A,B),C).
A = _G187
B = _G188
C = _G187, _G188
There isn't much rule or consensus on the clauses you can access using
clause/2. The only rule is that clause/2 works on dynamic predicates.
Beyond that, all bets are off. This isn't a real problem.
Besides the usual exercise in Prolog meta-programming generally
resulting in very much broken meta-interpreters there isn't much point
in using clause/2 for anything but environment support predicates such
as listing (basically clause/2 followed by portray_clause/1).
SWI-Prolog is very generous, in the sense that clause/2 succeeds on
anything but predicates defined in C. Its up to the user to decide
how to use it. If you have a meta-interpreter handling ,/2 you
shouldn't be calling clause/2 as well and hope it says 'no'. So,
the code becomes
prove((A,B)) :- !, % things we meta-interpret
prove(A),
prove(B).
.....
prove(Head) :- % things with inspectable clauses
clause(Head, Body), !,
prove(Body).
prove(Head) :- % all the rest
Head.
Richard O'Keefe has provided a decent meta-interpreter implementation
capable of handling the cut. Have a look at that if you are serious on
meta-interpretation.
Cheers --- Jan
P.s. Current SWI-Prolog still has a rule (A,B) :- A, B. This is why
clause/2 succeeds. Actually this rule serves no purpose anymore
and could be deleted. I think I'll leave it in, just make students
aware of the issues :-)
.
- References:
- Strange clause/2 predicate behaviour in SWI-Prolog
- From: Jose' de Siqueira
- Strange clause/2 predicate behaviour in SWI-Prolog
- Prev by Date: Re: Strange clause/2 predicate behaviour in SWI-Prolog
- Next by Date: Re: How to solve the following ``Liars'' puzzle in prolog?
- Previous by thread: Re: Strange clause/2 predicate behaviour in SWI-Prolog
- Index(es):