1 A C++ interface to SWI-Prolog (Version 1)
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog (Version 1)
          • Introduction
          • Overview
          • Examples
          • The class PlTerm
          • The class PlTermv
          • Supporting Prolog constants
          • The class PlRegister
          • The class PlQuery
          • The PREDICATE macro
          • Exceptions
          • Embedded applications
          • Considerations
          • Conclusions

1.2 Overview

The most useful area for exploiting C++ features is type-conversion. Prolog variables are dynamically typed and all information is passed around using the C-interface type term_t. In C++, term_t is embedded in the lightweight class PlTerm. Constructors and operator definitions provide flexible operations and integration with important C-types (char *, wchar_t*, long and double).

The list below summarises the classes defined in the C++ interface.

PlTerm
Generic Prolog term. Provides constructors and operators for conversion to native C-data and type-checking.
PlString
Subclass of PlTerm with constructors for building Prolog string objects.
PlCodeList
Subclass of PlTerm with constructors for building Prolog lists of ASCII values.
PlCharList
Subclass of PlTerm with constructors for building Prolog lists of one-character atoms (as atom_chars/2).
PlCompound
Subclass of PlTerm with constructors for building compound terms.
PlTail
SubClass of PlTerm for building and analysing Prolog lists.
PlTermv
Vector of Prolog terms. See PL_new_term_refs(). the [] operator is overloaded to access elements in this vector. PlTermv is used to build complex terms and provide argument-lists to Prolog goals.
PlException
Subclass of PlTerm representing a Prolog exception. Provides methods for the Prolog communication and mapping to human-readable text representation.
PlTypeError
Subclass of PlException for representing a Prolog type_error exception.
PlDomainError
Subclass of PlException for representing a Prolog domain_error exception.
PlExistenceError
Subclass of PlException for representing a Prolog existence_error exception.
PlPermissionError
Subclass of PlException for representing a Prolog permission_error exception.
PlAtom
Allow for manipulating atoms in their internal Prolog representation for fast comparison.
PlQuery
Represents opening and enumerating the solutions to a Prolog query.
PlFrame
This utility-class can be used to discard unused term-references as well as to do‘data-backtracking’.
PlEngine
This class is used in embedded applications (applications where the main control is held in C++). It provides creation and destruction of the Prolog environment.
PlRegister
The encapsulation of PL_register_foreign() is defined to be able to use C++ global constructors for registering foreign predicates.

The required C(++) function header and registration of a predicate is arranged through a macro called PREDICATE().