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

3 Examples
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • Examples
          • Hello(World)
          • Adding numbers
          • Average of solutions

3.1 Hello(World)

This simple example shows the basic definition of the predicate hello/1 and how a Prolog argument is converted to C-data:

PREDICATE(hello, 1)
{ cout << "Hello " << (char *)A1 << endl;

  return TRUE;
}

The arguments to PREDICATE() are the name and arity of the predicate. The macros A<n> provide access to the predicate arguments by position and are of the type PlTerm. Casting a PlTerm to a char * or wchar_t * provides the natural type-conversion for most Prolog data-types, using the output of write/1 otherwise:

?- hello(world).
Hello world

Yes
?- hello(X)
Hello _G170

X = _G170

ClioPatria (version V3.1.1-40-g9d9e003)