- Documentation
- Reference manual
- Packages
- A C++ interface to SWI-Prolog
- A C++ interface to SWI-Prolog (Version 2)
- Overview of accessing and changing values (version 2)
- Converting PlTerm to native C and C++ types (version 2)
- Unification (version 2)
- Comparison (version 2)
- Analysing compound terms (version 2)
- Miscellaneous (version 2)
- The class PlTerm_string (version 2)
- The class PlCodeList (version 2)
- The class PlCharList (version 2)
- The class PlCompound (version 2)
- The class PlTail (version 2)
- The class PlTermv (version 2)
- The class PlAtom - Supporting Prolog constants (version 2)
- Classes for the recorded database: PlRecord and PlRecordExternalCopy
- Overview of accessing and changing values (version 2)
- A C++ interface to SWI-Prolog (Version 2)
- A C++ interface to SWI-Prolog
2.10.4 Analysing compound terms (version 2)
Compound terms can be viewed as an array of terms with a name and
arity (length). This view is expressed by overloading the
operator.
[]
A type_error
is raised if the argument is not compound
and a
domain_error
if the index is out of range.
In addition, the following functions are defined:
- PlTerm PlTerm::operator[](int arg)
- If the
PlTerm
is a compound term and arg is between 1 and the arity of the term, return a newPlTerm
representing the arg-th argument of the term. IfPlTerm
is not compound, atype_error
is raised. Id arg is out of range, adomain_error
is raised. Please note the counting from 1 which is consistent to Prolog's arg/3 predicate, but inconsistent to C's normal view on an array. See also classPlCompound
. The following example tests x to represent a term with first-argument an atom or string equal tognat
...., if ( x[1] == "gnat" ) ...
- const char * PlTerm::name()
- Return a
const char *
holding the name of the functor of the compound term. Raises atype_error
if the argument is not compound. - size_t PlTerm::arity()
- Returns the arity of the compound term. Raises a
type_error
if the argument is not compound.