- Documentation
- Reference manual
- Packages
- A C++ interface to SWI-Prolog
- A C++ interface to SWI-Prolog (Version 2)
- Summary of changes between Versions 1 and 2
- Sample code (version 2)
- Introduction (version 2)
- The life of a PREDICATE (version 2)
- Overview (version 2)
- Examples (version 2)
- Rationale for changes from version 1 (version 2)
- Porting from version 1 to version 2
- The class PlFail (version 2)
- Overview of accessing and changing values (version 2)
- The class PlRegister (version 2)
- The class PlQuery (version 2)
- The PREDICATE and PREDICATE_NONDET macros (version 2)
- Exceptions (version 2)
- Embedded applications (version 2)
- Considerations (version 2)
- Conclusions (version 2)
- A C++ interface to SWI-Prolog (Version 2)
- A C++ interface to SWI-Prolog
2.2 Sample code (version 2)
The file test_cpp.cpp contains examples of Prolog predicates written in C++. This file is used for testing (called from test_cpp.pl). Notable examples:
- add_num/3 -
same as
A3 is A1+A2
, converting the sum to an integer if possible. - name_arity/3 - C++ implementation of functor/3.
- average/3 - computes the average of all the solutions to Goal
- can_unify/2 - tests whether the two arguments can unify with each other, without instantiating anything (similar to unifiable/3).
- eq1/1, eq2/2, eq3/2 - three different ways of implementing =/2.
- write_list/1 - outputs the elements of a list, each on a new line.
- cappend/3 - appends two lists (requires that the two lists are instantiated).
- square_roots/2
- same as
bagof(Sqrt, X^(between(0,4,X), Sqrt is sqrt(X)), A2)
. - range_cpp/3 - on backtracking, generates all integers starting at A1 and less than A2 (that is, one less than between/3).
- int_info/2 - on backtracking generates all the integral types with their minimum and maximum values.
The file
likes.cpp
contains a simple program that calls the Prolog predicate likes/2
and
happy/1 (these
predicates are defined in
likes.pl.
The usage and how to compile the code are in comments in likes.cpp