Re: [eclipse-users] more questions although there are no replies :(

From: Joachim Schimpf <j.schimpf_at_crosscoreop.com>
Date: Tue, 31 Oct 2006 21:03:43 +0000
J. Manuel Velasco wrote:
> 
> Can't I compile the prolog code like that:
>     post_goal(term(EC_functor("compile", 1), "familia"));
> 
> and then make questions from C/C++ ???

Here is an example (on Linux):


% file foo.ecl
twice(X,Y) :- Y is 2*X.



// file ex.cc
#include	"eclipseclass.h"
#include	<iostream>

using namespace std;

main()
{
	ec_init();

	post_goal(term(EC_functor("compile",1),"foo"));
	if (EC_resume() != EC_succeed)
	{
	    cout << "Compilation failed\n";
	    exit(-1);
	}

	EC_ref Result;
	post_goal(term(EC_functor("twice",2), 123, Result));

	if (EC_resume() == EC_succeed)
	{
	    long i;
	    if (EC_word(Result).is_long(&i) == EC_succeed)
		cout << i << "\n";
	    else
		cout << "unexpected result type";
	}
	else
	{
	    cout << "goal failed";
	}

	ec_cleanup();
}


Compile the C++ file (change path names according to your installation):

% g++ -o ex ex.cc -I/vol/Eclipse/5.10_33/include/i386_linux 
-L/vol/Eclipse/5.10_33/lib/i386_linux -leclipse


Run the resulting executable ex:

asterix% LD_LIBRARY_PATH=/vol/Eclipse/5.10_33/lib/i386_linux 
ECLIPSEDIR=/vol/Eclipse/5.10_33 ./ex
246


-- Joachim
Received on Tue Oct 31 2006 - 21:04:21 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:57 CET