From Antoine.GALLAND@gemplus.com Thu Oct  4 14:39:27 2001
Received: from croot.gemplus.com (croot.gemplus.com [195.25.133.234])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f94CdRt18083
	for <prolog@swi.psy.uva.nl>; Thu, 4 Oct 2001 14:39:27 +0200 (MET DST)
Received: from mail-stdby.gemenos.eur.gemplus.com (unknown [172.16.101.150])
	by croot.gemplus.com (Postfix) with ESMTP id E01565E121
	for <prolog@swi.psy.uva.nl>; Thu,  4 Oct 2001 14:43:30 +0100 (WET DST)
Received: from [172.28.50.87] by mail-stdby.gemenos.eur.gemplus.com with ESMTP for prolog@swi.psy.uva.nl; Thu, 4 Oct 2001 14:37:08 +0200
Message-Id: <3BBC5725.6D52703E@gemplus.com>
Date: Thu, 04 Oct 2001 14:33:41 +0200
From: Antoine GALLAND <Antoine.GALLAND@gemplus.com>
Organization: Gemplus Research Labs
X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
To: prolog@swi.psy.uva.nl
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Subject: [SWIPL] C++ SWI Prolog interface

Hi,

I'm trying to interface Prolog code into C or C++ code.
For the moment I just test little examples.

I've tested with success the C++ package "SWI-cpp.h" from
http://www.swi.psy.uva.nl/projects/SWI-Prolog/packages/cpp/
on linux using gcc 2.95.3 and SWI-prolog 4.0.9
But the example is quite simple.

1) Is someone have some code or example using C/C++ code to interface
with SWI prolog compiler (plld).
-> some example with only C/C++ code
-> some example interfacing C++ code AND prolog code (in prolog file
.pl)

2) Here one of my example which doesn't work and I don't understand why
:
in file main.cpp :
-----
#include "SWI-cpp.h"
#include <iostream.h>

int main(int argc, char **argv)
{

  PlEngine e(argv[0]);

  try {

    PlTermv av(1);
    PlCompound compound("hello",PlTermv("world"));
    av [0] = compound;

    PlQuery q("compound", av);
    while( q.next_solution() )
      cout << "\t" << (char *) av[0] << endl;

    if ( PlCall("compound", av) )
      cout << "YES" << endl;
    else
      cout << "NO" << endl;


  } catch ( PlException &ex )
    {
      cerr << (char *) ex << endl;
      exit(1);
    }
}
------

my compilation line is:
plld -o test -ld g++ -goal true main.cpp

------
And here the log of the call : ./test

bash-2.04$ ./test
        hello(world)
test: pl-wam.c:1491: PL_open_query: Assertion `(unsigned
long)((&PL_local_data)->foreign_environment) > (unsigned
long)((&PL_local_data)->environment)' failed.
Aborted

----

* I don't undertand why the query crash, normaly in SWI-prolog you can
write :
?- compound(hello(world)).

Yes

* In fact my problem is more larger : How to construct in C++ big
(complex) term and transfer them to a prolog file queries.
I've test with sucess some call in C++ to a prolog file but when I try
make more complex term, I have always the same exception (mention
before) :

Thank you by advance for your help,

Cordialy,

Antoine Galland




