|
int Start_Prolog (int argc, char *argv[]) void Stop_Prolog (void) void Reset_Prolog (void) Bool Try_Execute_Top_Level(void)
int main(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) return 0; if (nb_user_directive) return 0; printf("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; }
|
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).
int main(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; arg[0]=Mk_Variable(); arg[1]=Mk_String(str); nb_sol=0; res=Pl_Query_Start(func, 2, arg, TRUE); 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; }
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