next up previous contents index
Next: 6.11 Information about the Up: 6. Standard Predicates Previous: 6.9.1 Tabling Aggregate Predicates   Contents   Index


6.10 Meta-Predicates

call(#X)

If X is a non-variable term in the program text, then it is executed exactly as if X appeared in the program text instead of call(X), e.g.
$\ldots$, p(a), call( (q(X), r(Y)) ), s(X), $\ldots$
is equivalent to
$\ldots$, p(a), q(X), r(Y), s(X), $\ldots$
However, if X is a variable in the program text, then if at runtime X is instantiated to a term which would be acceptable as the body of a clause, the goal call(X) is executed as if that term appeared textually in place of the call(X), except that any cut (`!') occurring in X will remove only those choice points in X. If X is not instantiated as described above, an error message is printed and call/1 fails.

Error Cases

instantiation_error
X is a variable
type_error(callable,X)
X is not callable.

#X

(where X is a variable) executes exactly the same as call(X). However, the explicit use of call/1 is considered better programming practice. The use of a top level variable subgoal elicits a warning from the compiler.

once(#X)

once/1 is defined as once(X):- call(X),!. once/1 should be used with care in tabled programs. The compiler can not determine whether a tabled predicate is called in the scope of once/1, and such a call may lead to runtime errors. If a tabled predicate may occur in the scope of once/1, use table_once/1 instead.

Error cases are the same as call/1.

table_once(#X)

table_once/1 is a weaker form of once/1, suitable for situations in which a single solution is desired for a subcomputation that may involve a call to a tabled predicate. table_once(?Pred) succeeds only once even if there are many solutions to the subgoal Pred. However, it does not ``cut over'' the subcomputation started by the subgoal Pred, thereby ensuring the correct evaluation of tabled subgoals.


next up previous contents index
Next: 6.11 Information about the Up: 6. Standard Predicates Previous: 6.9.1 Tabling Aggregate Predicates   Contents   Index
Terrance Swift 2007-10-05