Re: [eclipse-clp-users] ECLiPSe - C/C++ interaction

From: Yngwie <>
Date: Wed, 11 Feb 2009 16:44:44 +0100
Giuseppe Di Guglielmo wrote:
> Dear all,
> I am developing a C/C++ module which has to interact with ECLiPSe. 
> A first solution is to look at "Embedding and Interfacing Manual", but I'd
> like to open something like a pipe or a socket versus ECLiPSe to directly
> write my predicates in Prolog and submit them to ECLiPSe. Moreover I have to
> retrieve the results from ECLiPSe to C/C++. How can do it? Does exist any
> example?
> C/C++ module ---> communication channel ---> ECLiPSe
>        ^               Prolog                    |
>        |-------- communication channel <---------|                    
> Best regards,
> Giuseppe
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
Hi Giuseppe,
I realized something like that in a web application context in PHP.
Even if the platform is different, I hope my experience could help you somehow.
I used sockets as communication channel and EXDR (described in ECLiPSe
Embedding and Interfacing Manual) as a language for representing terms;
a formal grammar for EXDR is reported in ECLiPSe manual and is an LL(1) grammar,
so it's quite easy to parse.

For the communication part, initially I implemented the remote interface protocol
described in manual, but it was not too suited for my application needs
(i had to issue a Prolog goal nearly for each http request from client side,
and so my communication was not session oriented, but for you it could not be the same).
After asking on this mailing list, I dropped this way and implemented a simpler
model where the Prolog side is put in the classic iterative server accept loop, and
handles one request a time (for now it's ok for me).

What I've done is write an EXDR parser/generator
for my application platform (PHP in my case), and write a socket server
in ECLiPSe to handle requests in a loop like this:

listen :-
	new_socket_server(Socket, localhost/<port>, <backlog queue size>), accept_loop(Socket).

accept_loop(Socket) :-
	accept(Socket, localhost/_, ConSocket),
	read_exdr(ConSocket, Goal), Goal, write_exdr(ConSocket, Goal),

When a client completes the TCP handshaking, the Prolog server accepts the connection and
waits for a term in EXDR format; executes goal G, writes the instantiated goal out to
the connection socket and close the connection.

This is only an example and I hope it could be useful to you.

Best regards,
Andrea Montemaggio
Received on Wed Feb 11 2009 - 15:44:48 CET

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