2.9 The class PlTerm (version 2)
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog (Version 2)
          • The class PlTerm (version 2)
            • Constructors (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 PlTermString (version 2)
            • The class PlCodeList (version 2)
            • The class PlCharList (version 2)
            • The class PlCompound (version 2)
            • The class PlTail (version 2)

2.9.4 Unification (version 2)

See also section 2.12.

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(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 PlCheck() to raise an exception if the unification fails.

PREDICATE(hostname2, 1)
{ char buf[256];
  PlCheck(gethostname(buf, sizeof buf) == 0);
  PlCheck(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.