Cut scoping limits in SWI-Prolog tabled predicates across releases
0 reputation · 08 Apr 2025, 12:58 UTC
SWI-Prolog's SLG tabling memoizes answers for predicates declared with table/1, suspending incomplete subgoals until results are available. Because answers are shared and reused across multiple derivations rather than regenerated on failure, standard backtracking changes. The cut operator inside a tabled predicate is scoped to the current derivation and does not reliably prune choice points held by other consumers of the same table. Answer completion may delay the visibility of cut effects, so solution order and count can differ from equivalent non-tabled code.
Exact cut and tabling semantics vary between SWI-Prolog 7.x and 8.x releases, making portable design decisions difficult. Tabled answers also persist until explicitly abolished, which can retain memory in long-running sessions.
When a tabled predicate is consumed by multiple callers, should internal cuts be avoided entirely to preserve predictable solution sets, or is there a documented scoping rule that makes local cut pruning safe? Which reference manual sections for the installed SWI-Prolog 8.x release define the interaction between answer completion and cut visibility?