Thank you for your answer sir! Apparently one of the problem I was having was the use of PlTerm_var in order to go through the list.
Although, the examples provided within the repository arenāt all that helpful in my use case. I also mean to clarify my issue since in the previous post I was kinda hasty and Iām sorry for that.
What Iām trying to do is to use my prolog knowledge base within a cpp environment. To be more precise, I want to run the prolog engine, provide a query to it and be able to get and manage the answer. I did, however, run into a problem when trying to create a prolog list. Iād like to create a list, give it to the engine using the PlQuery object, and get the answer.
All of this has to be made somewhere within the project, in my case itās the main funcion and also all the project (which Iām using to test the environment):
#include "SWI-cpp2.h"
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
if (_putenv("SWI_HOME_DIR=C:\\Program Files\\swipl")) return 0;
if (!PL_initialise(argc, argv))
PL_halt(1);
PlCall("consult('smallProject.pl')",NULL);
string phrase[5] = { "the","woman","likes","the","man" };
PlTermv av(2);
PlTerm_tail l(av[1]);
try {
for (int i = 0; i < 5; i++) {
PlTerm t(PlAtom(phrase[i].c_str()));
if (l.append(t)) cout << "element " << i <<" inserted, being: "<< t.as_string() <<"\n";
}
if (!l.close()) cerr << "error occurred\n";
PlTerm_var e;
while (l.next(e))
cout << "list element: " << e.as_string() << ";\n";
PlQuery q("smallProject:main", av);
int res = q.next_solution();
cout << "out: " << av[0].as_string() << "\n";
switch (res) {
case PL_S_NOT_INNER:
cout << "error PL_S_NOT_INNER\n";
break;
case PL_S_EXCEPTION:
cout << "error PL_S_EXCEPTION\n";
break;
case PL_S_FALSE:
cout << "no\n";
break;
case PL_S_TRUE:
cout << "yes\n";
break;
case PL_S_LAST:
cout << "last\n";
break;
default:
cout << "default\n";
break;
}
cout << av[0].as_string() << "\n";
}
catch (const PlException& e) {
cerr << e.what() << "\n";
}
}
the purpose of this main is to test the functionalities of the interface, now Iām stuck with PlTerm_tail. Apparently the list is empty although the append calls didnāt raise any errors.
I also want to clarify that I canāt use the swipl-ld or any kind of compiler option for my project. Hence Iām using the Visual Studio environment with copies of the header files: SWI-cpp2.h, SWI-cpp2-atommap.h, SWI-cpp2-plx.h, SWI-Prolog.h and SWI-Stream.h. And a single resource file: libswipl.dll.a.
The smallProject.pl file has a rule main/2 that wants a list as the second argument and gives, in output, a complex term as the first argument, if i make the query main(T,[ ]). I get āfalseā. If I make the query main(T,[the,woman,likes,the,man]). I get T = s(np(det(the), n(woman)), vp(v(likes), np(det(the), n(man)))). I donāt think providing the full knowledge base is crucial to solving my problem.
When I run the main.cpp file i get this output:
element 0 inserted, being: the
element 1 inserted, being: woman
element 2 inserted, being: likes
element 3 inserted, being: the
element 4 inserted, being: man
out: _
no
_
Maybe in my scenario I shouldnāt use PlTerm_tail? Is there another way to create a prolog list object? Thank you for your patience.