Install/use swi-prolog for C++

The “new” C++ API is SWI-cpp2.h is no longer a “work in progress” but is finished. It’s documented here – this might not yet have been refreshed to the very latest, and I need to proof-read it.

Simple examples are in the documentation and also in the files test_cpp.cpp and test_cpp.pl. As @EricGT mentioned, the rocksdb pack is a more complex example: Use more C++ features by kamahen · Pull Request #18 · JanWielemaker/rocksdb · GitHub (I’ve mostly finished modifying the code into a more “natural” C++ style; and I’ve also added some features to the library in the process0>

For Prolog-calling-C++, almost every piece of C functionality has a corresponding piece of C++ functionality. In addition, the C++ API extends the C API by handling C++ exceptions, and by taking advantage of C++'s RAII (Resource Acquisition Is Initialization) to simplify error handling and cleanup. For example, the C++ code for non-deterministic predicates is considerably simpler than the equivalent C code; and the new “blob” interface tries to have suitable defaults for almost everything, so that a “blob” can be defined by just a few lines of boilerplate.

For C++ calling Prolog, the story is a bit less complete, mainly because I don’t currently have much need for it. The basics work fine, but if you need some of the more advanced capabilities, you might need to drop into C. If that’s the case, please open an issue against GitHub - SWI-Prolog/packages-cpp: The SWI-Prolog C++ interface

The discussion around my changes to the C++ API are mostly here: Changes to SWI-cpp.h

1 Like