another problem interfacing prolog and C

Erick Alphonse <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Hello,

Still playing with the interface, I would like to call C from prolog and 
then from this C function call prolog back. Unfortunately, I can't get 
it working.

% examp.pl
:- initialization(top).

:- foreign(call_c(+term,-term)).

top :-
         call_c(a,_L).

% examp_c.c
#include <string.h>
#include "gprolog.h"

Bool
call_c(PlTerm In,PlTerm* Out)
{
   Pl_Query_Begin(TRUE);
   Pl_Query_Call(Find_Atom("write"),1,&In);
   Pl_Query_End(PL_RECOVER);

   *Out = Mk_Atom(atom_nil);

   return PL_SUCCESS;
}

And I get :
874# gplc examp.pl examp_c.c
875# ./examp
warning: /home/alphonse/tmp/bug-prolog/examp.pl:1: user directive failed
a
GNU Prolog 1.2.18
By Daniel Diaz
Copyright (C) 1999-2004 Daniel Diaz
| ?-

That is, the variable _L in top/0 cannot be unified at the exit of 
call_c, like if the inner query was messing with the stack. If I comment 
the inner query, it works of course. Could someone help me out and tell 
me if, first, what I try to do is possible with the gprolog interface 
and how to do it properly? I can't figure it out myself as I guess I 
exhausted all the examples in the doc.

Thanks in advance for your help, hopefully I could get back to work.

Erick.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.