int Start_Prolog (int argc, char *argv[]) void Stop_Prolog (void) void Reset_Prolog (void) Bool Try_Execute_Top_Level(void)
int Main_Wrapper(int argc, char *argv[]) { int nb_user_directive; Bool top_level; nb_user_directive = Start_Prolog(argc, argv); top_level = Try_Execute_Top_Level(); Stop_Prolog(); if (top_level || nb_user_directive) return 0; fprintf(stderr, "Warning: no initial goal executed\n" " use a directive :- initialization(Goal)\n" " or remove the link option --no-top-level" " (or --min-bips or --min-size)\n"); return 1; } int main(int argc, char *argv[]) { return Main_Wrapper(argc, argv); }
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).
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); }
Enter a name (or 'end' to finish): john solution: peter solution: bob solution: jane solution: mary solution: paul 5 solution(s) Enter a name (or 'end' to finish): mary solution: bob solution: jane 2 solution(s) Enter a name (or 'end' to finish): end