• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

1.11 Overview of accessing and changing values
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog
          • Overview of accessing and changing values
            • Converting PlTerm to native C and C++ types
            • Unification
            • Comparison
            • Analysing compound terms
            • Miscellaneous
            • The class PlTerm_string
            • The class PlCodeList
            • The class PlCharList
            • The class PlCompound
            • The class PlTerm_tail
            • The class PlTermv
            • The class PlAtom - Supporting Prolog constants
            • Classes for the recorded database: PlRecord and PlRecordExternalCopy

1.11.2 Unification

See also section 1.13.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.

ClioPatria (version V3.1.1-51-ga0b30a5)