Unable to get multiple answers using Pl_Query_Next_Solution
Lindsey Spratt <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.bugs |
|---|---|
| Message-ID | <[email protected]> |
I have a simple case where Pl_Query_Next_Solution returns only the first solution, when there should be two solutions. Gprolog version 1.2.16, on Mac OS X 10.2.3. In my modified version of gprolog (using the patches I sent you, compiled with debugging turned on), this produces the correct answer. Lindsey Spratt http://homepage.mac.com/lspratt _______________________________________________ Bug-prolog mailing list [email protected] http://mail.gnu.org/mailman/listinfo/bug-prolog
choice_point_bug7_main.c
(application/applefile, 84 B) - not displayed
choice_point_bug7_main.c
(text/plain, 3.6 KB)
/*-------------------------------------------------------------------------*
* GNU Prolog *
* *
* Part : foreign facility test *
* File : choice_point_bug7_main.c *
* Descr.: test file - C part
* Author: Lindsey Spratt (based on file by Daniel Diaz) *
* *
* Copyright (C) 2003 Lindsey Spratt *
* *
* GNU Prolog is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2, or any later version. *
* *
* GNU Prolog is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc. *
* 59 Temple Place - Suite 330, Boston, MA 02111, USA. *
*-------------------------------------------------------------------------*/
/*
* This version member/2.
*
* Create test with
* gplc -o choice_point_bug7 choice_point_bug7_main.c
* This version *works* with 1.2.16.mod (and prints out '2 solutions').
* This version *errors* with 1.2.16 with only 1 solution.
* this should have produced 2 solutions.
*/
#include <string.h>
#include "gprolog.h"
/*---------------------------------*
* Constants *
*---------------------------------*/
/*---------------------------------*
* Type Definitions *
*---------------------------------*/
/*---------------------------------*
* Global Variables *
*---------------------------------*/
/*---------------------------------*
* Function Prototypes *
*---------------------------------*/
/*-------------------------------------------------------------------------*
* MAIN *
* *
* See comments in EnginePl/main.c about the use of the wrapper function. *
*-------------------------------------------------------------------------*/
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;
PlTerm memberArgs[2];
PlTerm listTerms[2];
Start_Prolog(argc, argv);
Pl_Query_Begin(TRUE);
/* member(X, [a,b]) */
memberArgs[0] = Mk_Variable();
listTerms[0] = Mk_String("a");
listTerms[1] = Mk_String("b");
memberArgs[1] = Mk_Proper_List(2, listTerms);
func = Find_Atom("member");
nb_sol = 0;
res = Pl_Query_Call(func, 2, memberArgs);
while (res)
{
nb_sol++;
res = Pl_Query_Next_Solution();
}
Pl_Query_End(PL_RECOVER);
printf("%d solution(s)\n", nb_sol);
Stop_Prolog();
return 0;
}
int
main(int argc, char *argv[])
{
return Main_Wrapper(argc, argv);
}