This section discusses the functions for creating and manipulating queries from C. Note that a foreign context can have at most one active query. This implies it is allowed to make strictly nested calls between C and Prolog (Prolog calls C, calls Prolog, calls C, etc., but it is not allowed to open multiple queries and start generating solutions for each of them by calling PL_next_solution(). Be sure to call PL_cut_query() or PL_close_query() on any query you opened before opening the next or returning control back to Prolog.
NULL
,
the context module of the calling context will be used, or user
if there is no calling context (as may happen in embedded systems). Note
that the context module only matters for module_transparent
predicates. See context_module/1
and module_transparent/1.
The debug argument is normally TRUE
. If FALSE
is specified, the goal is run in `nodebug' mode, regardless of the
current debug mode. The p argument specifies the predicate,
and should be the result of a call to PL_pred() or PL_predicate(). Note
that it is allowed to store this handle as global data and reuse it for
future queries. The term-reference t0 is the first of a
vector of term-references as returned by PL_new_term_refs(n).
The example below opens a query to the predicate is_a/2 to find the ancestor of for some name.
TRUE
if a solution was found, or FALSE
to
indicate the query could not be proven. This function may be called
repeatedly until it fails to generate all solutions to the query.
TRUE
if the call succeeds, FALSE
otherwise.
Figure 9 shows an example to
obtain the number of defined atoms. All checks are omitted to improve
readability.