|
From: Narayan A. <nan...@ly...> - 2002-12-20 00:42:19
|
Hi,
I am trying to construct a simple example for querying the prolog engine from C++. The following is the simple prolog code (test.pl) to which I am trying to connect
% Prolog file test.pl for testing Connectivity from C %
% Receives a string and outputs the same %
receive(S):- write('I received '),write(S),nl.
relation(abe,john).
And, following is the C++ code:
void loadit(){
PlFrame fr;
PlTermv av(1);
av[0] = "test.pl";
PlQuery q("consult", av);
q.next_solution();
}
void start(){
PlTermv av(1);
av[0] = "message";
PlQuery q("receive",av);
q.next_solution();
}
int main( int argc, char *argv[] )
{
char *program = argv[0];
char *plav[2];
plav[0] = program;
plav[1] = NULL;
if ( !PL_initialise(1, plav) )
PL_halt(1);
loadit();
start();
return 0;
}
The above program works fine and I am able to get the output: "I received message" in the console. Now, my concern is to pass two arguments to the fact "relation", one of them is "abe" and other I want it to be a variable , so that I get the result "john" assigned to it. How do I construct such a query and how do I access the result and use it as a C data for other purposes?
Could someone please answer?
Thanks,
Narayan.
_____________________________________________________________
Get 25MB, POP3, Spam Filtering with LYCOS MAIL PLUS for $19.95/year.
http://login.mail.lycos.com/brandPage.shtml?pageId=plus&ref=lmtplus
|