next up previous contents index
Next: Skeletons and Predicate Specifications Up: Tabled Predicate Manipulations Previous: Tables and Table Entries   Contents   Index

Answers, Returns, and Templates

Given a table entry (S,$ \cal {A}$, Status), each answer in $ \cal {A}$ is maintained in XSB as an answer substitution, that is a substitution to the variables of S. The table inspection predicates allow access to answer substitutions through a term whose principle functor is ret/n, where n is the number of distinct variables in the producer subgoal. The order of arguments in ret/n corresponds to the order of distinct variables in a left-to-right traversal of S.

Example 6.13.1   Let S = p(X,f(Y)) be a producer subgoal and $ \alpha$ = {X=a,Y=b} be an answer substitution. The representation of $ \alpha$ as a return is ret(a,b) and the application of that return to S yields the answer p(a,f(b)).$ \Box$

In a similar manner, XSB maintains substitutions between producer subgoals and consuming subgoals when subsumption-based tabling is used. The return template for a consuming call is a substitution mapping variables of its producer to subterms of the call. This template can then be used to select returns from the producer which satisfy the consuming call. Note, then, that a return template of a subsumed subgoal may show partial instantiations. Return templates are also represented as ret/n terms in the manner described above.

Example 6.13.2   Let p/2 of the previous example be evaluated using subsumption and let S be present in its table. Further, let S1: p(A,f(B)) and S2: p(g(Z),f(b)) be two consuming subgoals of S. Then the return template of S1 is ret(A,B) and that of S2 is ret(g(Z),b). S1, being a variant of S, selects all returns of S such that {X=A,Y=B}. S2, on the other hand, selects only relevant answers of S, those where the returns satisfy {X=g(Z),Y=b}.$ \Box$


next up previous contents index
Next: Skeletons and Predicate Specifications Up: Tabled Predicate Manipulations Previous: Tables and Table Entries   Contents   Index
Luis Fernando P. de Castro 2003-06-27