next up previous contents index
Next: Potential Pitfalls in Tabling Up: Tabling in Definite Programs Previous: Variant and Subsumptive Tabling   Contents   Index


Cuts and Tabling

Tabling integrates well with most Prolog functionality, even for non-pure Prolog predicates. Meta-logical predicates like var/1, and predicates with side-effects like read/1 and write/1 can be used freely in tabled predicates as long as it is remembered that only the first call to a goal will execute program clauses: the rest will look up answers from a table.

The use of cuts with tabling is more problematic, as can be seen from the following exercise.

Exercise 5.2.4   Consider the program

:- table cut_p/1,cut_q/1,cut_r/0,cut_s/0.

cut_p(X):- cut_q(X),cut_r.
cut_r:- cut_s.
cut_s:- cut_q(_).
cut_q(1).       cut_q(2).

once(Term):- call(Term),!.
What solutions are derived for the goal ?- cut_p(X)? Suppose that cut_p/1 were rewritten as

cut\_p1(X):- cut\_q1(X),once(cut\_r1).

How should this cut over a table affect the answers generated for cut_p/1? What happens if you rewrite cut_p/1 in this way and compile it in XSB?

In Exercise 5.2.4, cut_p(1) and cut_p(2) should both be true. Thus, the cut in the once(cut_r1) literal in the revised may inadvertantly cut away solutions that are demanded by cut_p/1. Version 2.2 of XSB does not allow cuts over tabled predicates. XSB checks whether a tabled predicate statically lies in the scope of a cut at compile time. If so, the compilation is aborted5.2. At runtime, it also ensures that no incomplete tables are cut over whenever it executes a cut.

However, cuts are allowed within tabled predicates, subject (as always) to the restriction that the scope of a cut cannot include a call to a tabled predicate.

Example 5.2.2   An example of using cuts in a tabled predicate is a tabled meta-interpreter.

:- table demo/1.

demo(true).
demo((A,B)):-!,demo(A),demo(B).
demo(C):-call(C).
More elaborate tabled meta-interpreters can be extremely useful, for instance to implement various extensions of definite or normal programs.

In Version 2.2 of XSB a ``cut'' over tables occurs only when the user makes a call to a tabled predicate from the interpreter level, but does not generate all solutions. In such a case, the user will see the warning "Removing incomplete tables..." appear. Any complete tables will not be removed. They can be abolished by using one of XSB's predicates for abolishing tables.


next up previous contents index
Next: Potential Pitfalls in Tabling Up: Tabling in Definite Programs Previous: Variant and Subsumptive Tabling   Contents   Index
Baoqiu Cui
2000-04-23