The SWI-Prolog.h
header provides various functions for
accessing, setting, and unifying terms, atoms and other types.
Typically, these functions return a 0
(false
)
or
1
(true
) value for whether they succeeded or
not. For failure, there might also be an exception created - this can be
tested by calling PL_excpetion(0).
There are three major groups of methods:
The "put" operations are typically done on an uninstantiated term (see the PlTerm_var() constructor). These are expected to succeed, and typically raise an exception failure (e.g., resource exception) - for details, see the corresponding PL_put_*() functions in Constructing Terms.
For the "get" and "unify" operations, there are three possible failures:
false
return code
Each of these is communicated to Prolog by returning false
from the top level; exceptions also set a "global" exception term (using PL_raise_exception()).
The C++ programmer usually doesn't have to worry about this; instead
they can throw PlFail()
for failure or throw
PlException()
(or one of PlException
’s
subclasses) and the C++ API will take care of everything.