For Programmers: Free Programming Magazines  


Home > Archive > Prolog > March 2006 > Strange clause/2 predicate behaviour in SWI-Prolog









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Strange clause/2 predicate behaviour in SWI-Prolog
Jose' de Siqueira

2006-03-24, 7:07 pm

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

Yes

In GNU Prolog the same query gives:

GNU Prolog 1.2.16
By Daniel Diaz
Copyright (C) 1999-2002 Daniel Diaz
| ?- clause((A,B),C).

no

Shouldn't the same query give the same answer in both systems?
I consider the GNU Prolog answer expected and correct, but the
SWI-Prolog answer stuns me! Is it a bug?

--
José de Siqueira - Prof. Depto. de Ciência da Computação - UFMG
225 = 2 500 000 000 : The 225 richest people in the world earn
per year the same as the poorest 2,5 billion people. United Nations Report.

russell kym horsell

2006-03-24, 10:00 pm

Jose' de Siqueira <jose@dcc.ufmg.br> wrote:
> Shouldn't the same query give the same answer in both systems?

[playing with clause and ','/2].
> I consider the GNU Prolog answer expected and correct, but the
> SWI-Prolog answer stuns me! Is it a bug?


It may be considered "unusual" in terms of an appropriate measure of
possible Prolog implementations (:) but SWI isn't alone in adding as
a clause. It's documented in the SWI manual.
Jan Wielemaker

2006-03-25, 4:00 am

On 2006-03-24, Jose' de Siqueira <jose@dcc.ufmg.br> 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 :-)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com