pl_search_cpp is a C++ library that approximates Prolog predicates using a continuation-passing style. It provides a framework for defining and executing Prolog-like predicates, including support for backtracking, choice points, and unification.
- Prolog-like predicates
- Continuation-passing style execution
- Backtracking and choice points
- Unification of terms
- Support for variables, integers, floats, atoms, and lists
- C++11 or later
- CMake 3.10 or later
- Clone the repository:
git clone https://github.com/yourusername/pl_search_cpp.git
cd pl_search_cpp
- Create a build directory and navigate to it:
mkdir build
cd build
3: Run CMake to configure the project:
cmake ..
4: Build the project:
make
This will build the pl_search library and place it in the lib directory.
The examples directory contains the following examples of using the library.
- A solver for the SEND+MORE=MONEY puzzle with lots of comments about the approach and code details (
send_more_money.cpp
). - An example of a user defined Term type (
prolog_list.hpp
). - An implementation of the Prolog append predicate using the above type (
append_pred.hpp
). - A main program (
prolog_list.cpp
) that exercises the definitions above. - A Makefile to build the executables.
Documentation can be found here docs/index.html
This project is licensed under the MIT License - see the LICENSE file for details.
- 1.4
- Change from private to protected in term and pred classes to increase flexibility when subclassing. For example, termcolour can now be used in subclasses of various terms.
- 1.3
- Add an if-then-else predicate.
- 1.2
- Several (small) code optimizations - improved send_more_money by about 30%
- dynamic_cast<PInt*>(t.get()) is faster than dynamic_pointer_cast(t)
- redo PVar::dereference to avoid shared_ptr copies
- add Term* Term::deref_term() to avoid copying shared_ptr (for internal use)
- In Var::bind use raw pointer for pointer test
- change env_stack and trail_stack to use normal pointers
- Turned on -O2 optimization in cmake - approximately another 10% improvement
- Several (small) code optimizations - improved send_more_money by about 30%
- 1.1
- Fix problems in unify
- Remove the test_choice method from Pred
- merge solve into main in send_more_money.cpp for better testing with valgrind
- 1.0
- Initial release.