This module enhances aggregates by memorization. The table/1
directive has two effects. First of all a tabled predicate call is
materialized into a table by the given aggregate. This means for
example that duplicates are removed. Second, the materialized
table is memorized so that recurrent calls do not re-evaluate the
:- table concat/3.
concat(, X, X).
concat([X|Y], Z, [X|T]) :- concat(Y, Z, T).
?- concat(X, Y, [1,2,3]).
X = ,
Y = [1,2,3] ;
X = ,
Y = [2,3]
The table/1 directive accepts both a predicate indicators and a callable. If a predicate indicator is specified the given aggregate will be the empty aggregate nil/0. If a callable is specified the arguments of the callable specify the given aggregate. Multiple aggregate specifications will be automatically combined by the aggregate pairing operator (',')/2.Example:
:- table path(_,_,min).
path(X, X, 0).
path(X, Y, N) :- edge(X, Z), path(Z, Y, M), N is M+1.
?- path(a, e, X).
X = 2
?- path(a, e, 1).
The memorization stores the variant keys from the tabled predicate calls. Recursive tabled predicate calls are allowed and when completed extend the memorization store. The memorization store can be queried by the predicate current_table/2. Variant keys are not checked whether they subsume, so that specializations result in new variant keys.
The following tabling predicates are provided:
The following tabling predicate properties are provided: