Re: How call RAW text with Prolog predicate from C?
Daniel Diaz <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
You are right, the problem comes from: char str[]="asserta(parent(bob,mary))"; followed by: Pl_Mk_Atom(Pl_Create_Allocate_Atom(str)) you thus create an atom and not a compound term. You should use instead Pl_Mk_Compound instead (see http://gprolog.org/manual/html_node/gprolog069.html#toc291) BTW: since you have 2 nested compound terms (asserta/1 and parent/2) you have to first create parent(bob,mary) in a PlTerm variable 'X' and then to create asserta(X) into a variable 'goal'. Use Pl_Mk_Compound for both. Daniel [email protected] a écrit : > Is the listing C code: > > #include <stdio.h> > #include <string.h> > #define __GPROLOG_FOREIGN_STRICT__ > #include "gprolog.h" > int Main_Wrapper(int argc, char *argv[]) > { > PlTerm *args; > int functor, arity; > int iarity; > PlBool res; > PlTerm except; > > PlTerm goal; > char str[]="asserta(parent(bob,mary))"; > char *exceptstr; > > printf("0)\n"); > Pl_Start_Prolog(0, 0); > > > printf("1)\n"); > goal = Pl_Mk_Atom(Pl_Create_Allocate_Atom(str)); > > printf("2)\n"); > fflush(stdout); > > args = Pl_Rd_Callable_Check(goal, &functor, &arity); > > printf("3) functor: %d, arity: %d, args: %p\n", functor, arity, args); > fflush(stdout); > > Pl_Query_Begin(PL_TRUE); > res = (PlBool)Pl_Query_Call(functor, arity, args); > printf("4) res: %d\n", res); > fflush(stdout); > Pl_Query_End(PL_KEEP_FOR_PROLOG); > > Pl_Stop_Prolog(); > return 0; > } > int > main(int argc, char *argv[]) > { > return Main_Wrapper(argc, argv); > } > -- > > Is the output: > 0) > 1) > 2) > 3) functor: 781435, arity: 0, args: 00000000 > 4) res: 2 > -- > > res==2 - meaning PL_EXCEPTION. > > If str=="listing" then res == 1, and is OK. > > I think that the problem is that "asserta(parent(bob,mary))" not a Atom, is > Term. But "listing" is Atom. > The problem is that I do not know how to create(programatically) the > correct Term from string. > Or how to get gnu-prolog implement any str(programatically). > > Sorry for my bad English(russian). > On Thu, 23 Apr 2009 15:04:35 -0300, Cesar Rabak <[email protected]> > wrote: >> [email protected] escreveu: >>> Hello. I'am sorry for my bad English(russian). >>> >>> I want call from C application Prolog predicates. >>> I try that: >>> >>> PlTerm goal; >>> .... >>> Pl_Start_Prolog(0, 0); >>> >>> char str[]="asserta(parent(bob,mary))"; //or ANYthing else in string >>> format. >>> >>> goal = Pl_Mk_Atom(Pl_Create_Allocate_Atom(str)); >>> >>> args = Pl_Rd_Callable_Check(goal, &functor, &arity); >>> >>> Pl_Query_Begin(PL_TRUE); >>> >>> Pl_Query_Call(functor, arity, args); >> Where are you checking the return of Pl_Query_Call? >> >> >> > > > > _______________________________________________ > Users-prolog mailing list > [email protected] > http://lists.gnu.org/mailman/listinfo/users-prolog > -- Ce message a ete verifie par MailScanner pour des virus ou des polluriels et rien de suspect n'a ete trouve.