In XSB, tables are designed so that they can be used transparently by
computations. However, it is often useful to be able to explicitly
inspect a table, or to alter its state. In the following predicates,
which are provided for this purpose, Skeleton refers to
information about the function and arity of a predicate. If p/2
is a predicate, its skeleton can be represented as
where arg1 and arg2 can be
any instantiation pattern. Thus the information derived from the
skeletons p(1,2) and p(A,B) would be the same.
The user should be aware that skeletons which are dynamically created (e.g. by functor/3) are located in usermod (cf. Section 3.3). In such a case, the tabling predicates below may not behave in the desired manner if the tabled predicates themselves have not been imported into usermod.
For the following program and table
|
|
| ?- get_calls(p(X,Y),Cs,Ret).
X = _864816
Y = 3
Cs = 2927152
Ret = ret(_864816);
X = 1
Y = _864644
Cs = 2927104
Ret = ret(_864644);
no
| ?- get_calls(p(1,Y),Cs,Ret).
Y = 3
Cs = 2927152
Ret = ret(1);
Y = _864620
Cs = 2927104
Ret = ret(_864620);
no
| ?- get_calls(p(Y,3),Cs,Ret).
Y = _864792
Cs = 2927152
Ret = ret(_864792);
Y = 1
Cs = 2927104
Ret = ret(3);
no
| ?- get_calls(p(1,3),Cs,Ret).
Cs = 2927152
Ret = ret(1);
Cs = 2927104
Ret = ret(3);
no
| ?- get_call(p(X,Y),Cs,Ret).
no
| ?- get_call(p(1,Y),Cs,Ret).
Y = _864620
Cs = 2927104
Ret = ret(_864620);
no
| ?- get_call(p(Y,3),Cs,Ret).
Y = _864792
Cs = 2927152
Ret = ret(_864792);
no
| ?- get_call(p(1,3),Cs,Ret).
no
This predicate does not provide any information about whether a table is complete. Use table_state to inquire about a table's state.
Calls to get_calls_for_table/2 for the example in get_calls/3 would act as follows
|?- get_calls_for_table(p(X,Y), Call).
X = _646608
Y = _646436
Call = p(1,_646724) ;
X = _646608
Y = _646436
Call = p(_646720,3) ;
no
| ?- get_calls_for_table(p(1,2), Call).
Call = p(1,_646676)
Call = p(_646672,3) ;
no
The second example backtracks through all entries in the table, since
only skeletal information is used from the first argument.
Exception:
One way of accessing subgoals and answers of the example in in get_calls/3 is as follows
| ?- get_calls(p(Y,3),Cs,Ret), get_returns(Cs,Ret).
Y = 2
Cs = 2561656
Ret = ret(2);
Y = 1
Cs = 2561656
Ret = ret(1);
Y = 1
Cs = 2559032
Ret = ret(3);
Y = 1
Cs = 2559032
Ret = ret(3);
no
This predicate creates fresh variables for the return, rather than unifying them with variables in the first argument. An explicit unification of a call with its return can be done if so desired.
Example: Let us continue from the example in get_calls_for_table/3.
| ?- get_returns_for_call(p(1,X), Return).
X = _646412
Return = p(1,_646628);
X = _646412
Return = p(1,2);
X = _646412
Return = p(1,3);
no
| ?- get_returns_for_call(p(X,Y), Return).
no
| ?- get_returns_for_call(p(1,2), Return).
no
Exception:
For the following program and table
|
|
| ?- get_residual(p(X,Y),List).
X = 1
Y = 2;
Z = [];
X = 1
Y = 3;
Z = [tnot(p(2,3))];
X = 2
Y = 3;
Z = [tnot(p(1,3))];
X = 1
Y = 3;
Z = [tnot(p(2,3))];
X = 2
Y = 3;
Z = [tnot(p(1,3))];
no
Note that incomplete tables are abolished automatically by the system on exceptions and when the interpreter level is resumed. In these cases, the user does not need to abolish tables to maintain correctness.
Exception:
Example:
Continuing the example started in the description of predicate get_calls_for_table/3 the call abolish_table_call(p(1,X)) would produce the table
| Call | Returns |
| p(X,3) | p(1,3) |
| p(2,3) |
Exception:
Exceptions: