Next: Foreign Code and
Up: The Foreign Include
Previous: Discarding Data
In some situations, callback is highly time-critical and needs to be
performed often on the same predicate. In these cases, Pl_call() may
be too slow as it involves building the gaol using various unification
calls and calling PL_call() that will again unpack the call-term. In
these cases the interface described in this section may be useful.
- predicate_t
- PL_predicate( functor_t, module_t)
Return a handle to the given predicate in the given module. If module_t
is NULL
, the current context module will be used. This call
always succeeds, possibly creating a handle to an undefined predicate.
- int
- PL_call_predicate( module_t, int debug, predicate_t, term_t *argv)
Use a predicate handle to call predicate with the given arguments.
The vector argv must point to a vector of Prolog terms with
enough elements for the predicate.
The module argument defines the context module of the goal if the
called predicate is module transparent. If this argument is specified is
NULL
, this is the current context module. If no context is
available it is the user
module. If the debug argument is
FALSE
, the call will be hidden from the Prolog debugger.
The module and debug arguments are in almost all normal
cases NULL
and TRUE
. They are needed for some internal
cases. PL_call_predicate() is the function containing the actual
Prolog Virtual Machine Interpreter, flattening the call-stack as far
as possible
The following example realises the same as the example from
figure
Figure: Using PL_call_predicate
Finally, the direct predicate interface provides some utility functions.
- int
- PL_predicate_arity( predicate_t)
Returns the number of arguments required by the predicate. The argument
vector provided to PL_call_predicate() should contain at least this
number of elements.
- atomic_t
- PL_predicate_name( predicate_t)
Returns an atom identifying the name of the predicate.
- functor_t
- PL_predicate_functor( predicate_t)
Functor description of the term. This is always the same as the first
argument of the PL_predicate() call used to find the predicate.
- module_t
- PL_predicate_module( predicate_t)
Returns a handle to the module in which the predicate is defined. Note
that this is not necessarily the same as the module handle used to
locate the predicate with PL_predicate() as the predicate may be
imported. As predicate modifications may change the import/export
relations, the return value may change between calls.
Next: Foreign Code and
Up: The Foreign Include
Previous: Discarding Data
Passani Luca
Tue Nov 14 08:58:33 MET 1995