I’m using SWI-Prolog version SWI-Prolog version 8.4.2 for x86_64-linux, with CLPFD.
My prolog code is very simple, it looks like this:
:- use_module(library(clpfd)).
example(N1, N2) :-
N1 #= 4,
N2 #= 1.
When I query the software using command line utility, the program works as expected.
?- findall([N1,N2],example(N1,N2),Z).
Z = [[4, 1]].
Now I want to use C++ code to retrieve the same findall query results. My C++ code looks like this:
int main(int argc, char **argv)
{
PlEngine engine(argv[0]);
try
{
cout << "Executing query..." << endl;
PlTermv avv(3);
avv[0] = PlCompound("[N1,N2]");
avv[1] = PlCompound("example(N1,N2)");
// Creates a PlQuery from the arguments generates the first next_solution() and destroys the query.
// Returns the result of next_solution() or an exception.
result = PlCall("findall", avv);
cout << "\t" << (char *) avv[2] << endl;
PlTail query_res_as_list(avv[2]);
PlTerm query_res_01;
int n = query_res_as_list.next(query_res_01);
cout << "\t" << (char *) query_res_01 << endl;
PlTail query_res_01_as_list(query_res_01);
PlTerm query_res_01_item;
n = query_res_01_as_list.next(query_res_01_item);
cout << "\t" << (char*) query_res_01_item << endl;
return 0;
}
catch ( PlException &ex )
{
cerr << (char *) ex << endl;
exit(1);
}
}
But what I’m getting is variables without the actual numbers I was expecting, namely 4 and 1:
Executing query...
[[_2098,_2104]]
[_2098,_2104]
_2098
Can someone help me understand what I am doing wrong?