1.4 The class PlTerm
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog (Version 1)
          • The class PlTerm
            • Constructors
            • Casting PlTerm to native C-types
            • Unification
            • Comparison
            • Analysing compound terms
            • Miscellaneous
            • The class PlString
            • The class PlCodeList
            • The class PlCharList
            • The class PlCompound
            • The class PlTail

1.4.3 Unification

int PlTerm::operator =(Type)
The operator = is defined for the Types PlTerm, long, double, char *, wchar_t* and PlAtom. It performs Prolog unification and returns TRUE if successful and FALSE otherwise.

The boolean return-value leads to somewhat unconventional-looking code as normally, assignment returns the value assigned in C. Unification however is fundamentally different to assignment as it can succeed or fail. Here is a common example.

PREDICATE(hostname, 1)
{ char buf[32];

  if ( gethostname(buf, sizeof(buf)) == 0 )
    return A1 = buf;

  return FALSE;
}