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