[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Interfacing Prolog and C: Pl_Query_Next_Solution fails
From: |
Yannick Estève |
Subject: |
Interfacing Prolog and C: Pl_Query_Next_Solution fails |
Date: |
Fri, 08 Jul 2005 14:41:46 -0000 |
Hi,
Working in natural langugage processing/speech recognition, I develop
a program using C and Prolog.
In my C source, I need to process results of Prolog queries, but the
Pl_Query_Next_Solution function fails: only the first solution
obtained using Pl_Query_Call is returned.
So, to be sure that my program is not the problem, I tried the
following example coming from the gnu prolog manual:
( see http://pauillac.inria.fr/~diaz/gnu-prolog/manual/
manual070.html#toc310 )
Prolog source:
parent(bob,mary).
parent(jane,mary).
parent(mary,peter).
parent(paul,peter).
parent(peter,john).
anc(X,Y):-parent(X,Y).
anc(X,Z):-parent(X,Y), anc(Y,Z).
C source:
#include <string.h>
#include "gprolog.h"
static int
Main_Wrapper(int argc, char *argv[])
{
int func;
WamWord arg[10];
char str[100];
char *sol[100];
int i, nb_sol = 0;
Bool res;
Start_Prolog(argc, argv);
func = Find_Atom("anc");
for (;;)
{
printf("\nEnter a name (or 'end' to finish): ");
scanf("%s", str);
if (strcmp(str, "end") == 0)
break;
Pl_Query_Begin(TRUE);
arg[0] = Mk_Variable();
arg[1] = Mk_String(str);
nb_sol = 0;
res = Pl_Query_Call(func, 2, arg);
while (res)
{
sol[nb_sol++] = Rd_String(arg[0]);
res = Pl_Query_Next_Solution();
}
Pl_Query_End(PL_RECOVER);
for (i = 0; i < nb_sol; i++)
printf(" solution: %s\n", sol[i]);
printf("%d solution(s)\n", nb_sol);
}
Stop_Prolog();
return 0;
}
int
main(int argc, char *argv[])
{
return Main_Wrapper(argc, argv);
}
As shown in the manual, the following behaviour should be observed:
Enter a name (or 'end' to finish): john
solution: peter
solution: bob
solution: jane
solution: mary
solution: paul
5 solution(s)
But, this is what I obtain:
Enter a name (or 'end' to finish): john
solution: peter
1 solution(s)
Can you help me?
Here some features about my workstation (MacOS X, Tiger)
OS: Darwin horus.univ-lemans.fr 8.1.0 Darwin Kernel Version 8.1.0:
Tue May 10 18:16:08 PDT 2005; root:xnu-792.1.5.obj~4/RELEASE_PPC
Power Macintosh powerpc
GNU Prolog version: Prolog top-Level (GNU Prolog) 1.2.16
GNU Prolog was installed using fink:
Package: gprolog
Version: 1.2.16
Revision: 1
Source: gnu
Source-MD5: d7fe87106cd3e7e770375f04dd0d14c2
DocFiles: ChangeLog COPYING INSTALL NEWS PROBLEMS README VERSION
ConfigureParams: --with-install-dir=%i --with-html-dir=%i/share/doc/%
n/html --with-doc-dir=%i/share/doc/%n/doc --without-links-dir --with-
examples-dir=%i/share/doc/%n/examples
CompileScript: (cd src; ./configure %c; make)
InstallScript: <<
(cd src; make install)
(cd src; rm %i/COPYING %i/VERSION %i/NEWS %i/ChangeLog)
<<
Description: Prolog (ISO) and constraint-solving language
License: GPL
Homepage: http://www.gnu.org/software/gprolog/
Maintainer: Lindsey Spratt <address@hidden>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Interfacing Prolog and C: Pl_Query_Next_Solution fails,
Yannick Estève <=