7.11 Tabling predicate reference
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Tabled execution (SLG resolution)
        • Tabling predicate reference
          • table/1
          • tnot/1
          • not_exists/1
          • tabled_call/1
          • current_table/2
          • untable/1
          • abolish_all_tables/0
          • abolish_private_tables/0
          • abolish_shared_tables/0
          • abolish_table_subgoals/1
          • abolish_module_tables/1
          • abolish_nonincremental_tables/0
          • abolish_nonincremental_tables/1
    • Packages
Availability:built-in
Source:- table(:Specification)
Prepare the predicates specified by Specification for tabled execution. Specification is a comma-list, each member specifying tabled execution for a specific predicate. The individual specification is either a predicate indicator (name/arity or name//arity) or head specifying tabling with answer subsumption.

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:

variant
Default. Create a table for each call variant.
subsumptive
Instead of creating a new table for each call variant, check whether there is a completed table for a more general goal and if this is the case extract the answers from this table. See section 7.5.
shared
Declare that the table shall be shared between threads. See section 7.9
private
Declare that the table shall be local to the calling thread. See section 7.9
incremental
Declare that the table depends on other tables and incremental dynamic predicates. See section 7.7.
dynamic
Declare that the predicate is dynamic. Often used together with 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.