users-prolog
[Top][All Lists]
Advanced

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

Re: How call RAW text with Prolog predicate from C?


From: pva
Subject: Re: How call RAW text with Prolog predicate from C?
Date: Fri, 24 Apr 2009 11:09:57 +0600
User-agent: RoundCube Webmail/0.2a

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 <address@hidden>
wrote:
> address@hidden 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?
> 
> 
>





reply via email to

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