Class Problem (c++ and prolog)
- by Joshua Green
I am using the C++ interface to Prolog (the classes and methods of SWI-cpp.h). For working out a simple backtracking that john likes mary and emma and sara:
likes(john, mary).
likes(john, emma).
likes(john, ashley).
I can just do:
{
PlFrame fr;
PlTermv av(2);
av[0] = PlCompound("john");
PlQuery q("likes", av);
while (q.next_solution())
{
cout << (char*)av[1] << endl;
}
}
This works in a separate code, so the syntax is correct. But I am also trying to get this
simple backtracking to work within a class:
class UserTaskProlog
{
public:
UserTaskProlog(ArRobot* r);
~UserTaskProlog();
protected:
int cycles;
char* argv[1];
ArRobot* robot;
void logTask();
};
This class works fine, with my cycles variable incrementing every robot cycle. However, when I run my main code, I get an Unhandled Exception error message:
UserTaskProlog::UserTaskProlog(ArRobot* r) : robotTaskFunc(this, &UserTaskProlog::logTask)
{
cycles = 0;
PlEngine e(argv[0]);
PlCall("consult('myFile.pl')");
robot->addSensorInterpTask("UserTaskProlog", 50, &robotTaskFunc);
}
UserTaskProlog::~UserTaskProlog()
{
robot->remSensorInterpTask(&robotTaskFunc);
// Do I need a destructor here for pl?
}
void UserTaskProlog::logTask()
{
cycles++;
cout << cycles;
{
PlFrame fr;
PlTermv av(2);
av[0] = PlCompound("john");
PlQuery q("likes", av);
while (q.next_solution())
{
cout << (char*)av[1] << endl;
}
}
}
I have my opening and closing brackets for PlFrame. I have my frame, my query, etc... The exact same code that backtracks and prints out mary and emma and sara. What am I missing here that I get an error message?
Here is what I think the code should do: I expect mary and emma and sara to be printed out once, every time cycles increments. However, it opens SWI-cpp.h file automatically and points to class PlFrame. What is it trying to tell me? I don't see anything wrong with my PlFrame class declaration.
Thanks,