#include <quintus/quintus.h>
     QP_pred_ref QP_predicate(name_string, arity, module_string)
     char *name_string;
     int   arity;
     char *module_string;


Before a Prolog predicate can be called from a foreign language it must be looked up. The C functions QP_predicate() and QP_pred() perform this function. The lookup step could have been folded into the functions that make the query, but if a predicate was to be called many times the redundant, if hidden, predicate lookup would be a source of unnecessary overhead. Instead, QP_predicate() or QP_pred() can be called just once per predicate. The result can then be stored in a variable and used as necessary.

Both QP_predicate() and QP_pred() return a QP_pred_ref(), which represents a Prolog predicate.

QP_predicate() is the most convenient way of looking up a callable Prolog predicate. It is simply passed the name and module of the predicate to be called as strings, the arity as an integer, and returns a QP_pred_ref(), which is used to make the actual call to Prolog.

QP_predicate() can only be used to look up predicates that have been declared callable from foreign code. If some other predicate, or a predicate that does not exist, is looked up, QP_ERROR is returned. This protects you from attempting to call a predicate that isn't yet ready to be called.

Return Value

a valid predicate reference
if the predicate called hasn't been declared callable or doesn't exist

See Also

QP_pred(), QP_query(), QP_open_query(), QP_next_solution(), QP_cut_query(), QP_close_query() fli-ffp