Although table/1 is normally used as a directive, SWI-Prolog allows calling it as a runtime predicate to prepare an existing predicate for tabled execution. The predicate untable/1 can be used to remove the tabling instrumentation from a predicate.
The example below prepares the predicate edge/2 and the non-terminal statement//1 for tabled execution.
:- table edge/2, statement//1.
Below is an example declaring a predicate to use tabling with answer subsumption. Answer subsumption or mode directed tabling is discussed in section 7.3.
:- table connection(_,_,min).
Additional tabling options can be provided using a term as/2, which can be applied to a single specification or a comma list of specifications. The options themselves are a comma-list of one or more of the following atoms:
incremental
.
This syntax is closely related to the table declarations used in XSB
Prolog. Where in XSB as
is an operator with priority above
the priority of the comma, it is an operator with priority below the
comma in SWI-Prolog. Therefore, multiple predicates or options must be
enclosed in parenthesis. For example:
:- table p/1 as subsumptive. :- table (q/1, r/2) as subsumptive.
tabled_call(Goal)
to create a table and
subsequently uses tnot/1
on the created table.
Logically, not_exists(p(X))
is defined as tnot(&existX(p(X)))
Note that each Goal variant populates a table for tabled_call/1. Applications may need to abolish such tables to limit memory usage or guarantee consistency‘after the world changed'.
:- table tabled_call/1 as variant. tabled_call(Goal) :- call(Goal).
Note that although using untable/1 followed by table/1 may be used to flush all tables associated with the given predicate(s), flushing tables should be done using one of the table abolish predicates both for better performance and compatibility with other Prolog implementations: abolish_all_tables/0, abolish_private_tables/0, abolish_shared_tables/0, abolish_module_tables/1 or abolish_table_subgoals/1. For example, to remove all tables for p/3 , run the goal below. The predicate functor/3 may be used to create a head term from a given name and arity.
?- abolish_table_subgoals(p(_,_,_)).
abolish_table_subgoals(und)
will also abolish the table for
p/0 because its answer refers to und/0 .
p :- und. und :- tnot(und).
skip
or error
. If Action
is skip
, do not delete the table.bugXSB
marks such tables for deletion after completion. That is not yet
implemented.