Re: Discriminating facts from rules



On 2008-05-14, guadalupegarciarubio@xxxxxxxxx <guadalupegarciarubio@xxxxxxxxx> wrote:
Hi all,

for efficiency reasons, I would like to match only a/1 facts in the
body of the rule b/2. Is there a non-ad-hoc way to do this?

The code that follows is a very simplified version of the real code:

a(1).
a(2).
a(X) :- %... a very expensive conjunction here

b(X) :- a(X). % I would like to match only a/1 facts, not rules.

Obviously, I call a/2 in other places of the code where I need to
match both a/2 facts and rules. Otherwise, I'd simply rename a/2
facts.

a_fact(X) :-
clause(a(X), true).

How this works out efficiencywise though is likely to be very
dependent on the Prolog engine (it may not use indexing, it may
decompile all bodies of matching heads before finding out the
unification with true fails, etc). Also, many systems don't allow
clause/2 on static code.

As you'd expect, Prolog isn't really designed for that. Splitting a/1
into a_cheap/1 and a_expensive/1 is the most obvious solution.

There are also other reasons too long to explain to keep a/2 facts and
rules under the same functor.

.... which you don't like :-)

Cheers --- Jan
.