users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newmain Ancestor example - help?


From: raptor
Subject: Newmain Ancestor example - help?
Date: Wed, 07 Apr 2004 13:54:51

Interfacing C to gprolog:

I have downloaded gprolog and the newmain Ancestor example. The code compiles and runs, but either generates an error or does not produce the expected results. Loading the newmail.pl file in the gprolog interpreter does work, so I don't think the problem is the .pl file.

The problem seems to be with the Pl_Query_End(PL_RECOVER). I tried changing it to use PL_KEEP_FOR_PROLOG, which runs, but does not give the correct set of solutions.

Has anybody else had this problem? Any recommendations or proposed fixes?

Below, I've provided information regarding the output, versions, source code etc. Any help here is appreciated.

Jeff.


1. newmain Output (with PL_RECOVER) - generates error

Enter a name (or 'end' to finish): peter

Fatal Error: Pl_Query_End(PL_RECOVER) but unrecoverable query

2. newmain Output (with PL_KEEP_FOR_PROLOG): - runs, but incorrectly.

Enter a name (or 'end' to finish): peter
solution: mary
solution: bob
solution: jane
3 solution(s)

Enter a name (or 'end' to finish):

3. the command used to compile:

gplc -C '-Wall -g' newmain.pl newmain.c

4. versions, etc.
Linux kernel version 2.4.18-14
(cc version 3.2 20020903
(Red Hat Linux 8.0 3.2-7))
Prolog compiler (GNU Prolog) 1.2.16

5. the newmain.pl file contains:

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).


6. the newmain.c source code.

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);
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]