[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Trying to make a generic VC++ function...
From: |
Joseph N. Fiore |
Subject: |
Trying to make a generic VC++ function... |
Date: |
Mon, 17 Feb 2003 08:25:01 -0500 |
Forgive my ignorance as I'm very new to GNU-Prolog and prolog in
general.
I'm trying to make a very generic VC++ function to call Prolog
functions.
It works with the new_main.pl example, ie when there are only two terms
to the function. But it doesn't work with three terms.
I want to call: plSolve("triple", "?X,bb,cc");
and it returns "aa,cc,dd;bb,cc,dd"
/* the Prolog file */
triple(aa,cc,dd).
triple(bb,cc,dd).
triple(cc,dd,ee).
triple(cc,bb,ee).
The problem is the call Rd_String(arg[i]). It segvaults whenever it
reaches a returned term that was a variable. Since I don't have a
version of the libraries compiled with debug, I can't trace into the
Rd_String call.
Any help would be greatly appreciated. I probably don't understand half
the GNU-Prolog functions even though I've been through the code quite a
bit.
Also: sorry for the largish code example but I removed as much as I
could
--Joe
// chaArgs: "aa,bb,?X,"
PROLOGINF_API char *plSolve(string chrPredicate, chrArgs)
{
WamWord arg[20];
// vectorize the chrArgs
// turn chrArgs "?X,?Y,bob" into a vector of three strings
vecArguments
plTokenize(chrArgs, ",", vecArguments);
// fill arg with vecArguments
// foreach iterArguments in vecArguments
int cntArguments = 0;
for (iterArguments = vecArguments.begin();
iterArguments != vecArguments.end();
iterArguments++)
{
// Process Variable
if (it starts with '?') {
arg[cntArguments] = Mk_Variable();
}
// Process constant
else {
arg[cntArguments] = Mk_String((char*)(*iterArguments).c_str());
}
cntArguments++;
}
int FindHandle = Find_Atom(chrPredicate);
Pl_Query_Begin(TRUE);
string retval = "";
int cntSolution = 0;
// Get first results
int Results = Pl_Query_Call(FindHandle, cntArguments, arg);
// While there are results to process
while (Results) {
// not first solution: append ";"
if (cntSolution) retval += ";";
cntSolution++;
// for all the returned arguments
for (int i = 0; i < cntArguments; i++)
{
// not first returned argument: append ","
if (i) retval += ",";
retval += Rd_String(arg[i]);
}
Results = Pl_Query_Next_Solution();
DBG(DARG,"Results: %d\n", Results);
}
Pl_Query_End(PL_RECOVER);
plResults = strdup(retval.c_str());
return plResults;
}
- Trying to make a generic VC++ function...,
Joseph N. Fiore <=