- 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.2 Unification (version 2)
See also section 2.12.1.
- bool PlTerm::unify_term(PlTerm)
- bool PlTerm::unify_atom(PlAtom)
- bool PlTerm::unify_atom(string)
- bool PlTerm::unify_list_codes(string)
- bool PlTerm::unify_list_chars(string)
- bool PlTerm::unify_integer(int)
- bool PlTerm::unify_float(double)
- bool PlTerm::unify_string(string)
- bool PlTerm::unify_functor(PlFunctor)
- bool PlTerm::unify_pointer(void *)
- bool PlTerm::unify_nil()
- bool PlTerm::unify_blob(PlBlob* blob)
- bool PlTerm::unify_blob(std::unique_ptr<PlBlob>* blob)
- Does a call to PL_unify_blob() and, if successful, calls
std::unique_ptr<PlBlob>::release() to pass
ownership to the Prolog blob; on failure or error, deletes the pointer
(ad calls its destructor). After either success and failure,
*blob==nullptr
. - bool PlTerm::unify_blob(void *blob, size_t len, PL_blob_t *type)
- bool PlTerm::unify_chars(int flags, size_t len, const char *s)
-
A family of unification methods are defined for the various Prolog types and C++ types. Wherever
string
is shown, you can use:char*
whar_t*
std::string
std::wstring
Here is an example:
PREDICATE(hostname, 1) { char buf[256]; if ( gethostname(buf, sizeof buf) == 0 ) return A1.unify_atom(buf); return false; }
An alternative way of writing this would use the PlCheckFail() to raise an exception if the unification fails.
PREDICATE(hostname2, 1) { char buf[256]; PlCheckFail(gethostname(buf, sizeof buf) == 0); PlCheckFail(A1.unify_atom(buf)); return true; }
Of course, in a real program, the failure of
gethostname(buf)sizeof buf should create an error term than
contains information from errno
.