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

From: Joachim Schimpf <jschimpf_at_users.sf.net>
Date: Fri, 13 Feb 2009 17:40:11 +1100
Yngwie wrote:
> 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
>>
>>   
> 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),
> 	close(ConSocket),
> 	accept_loop(Socket).
> 
> 
> 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


I would agree that for many applications Andrea's suggestion is a very good one.

In particular, when talking to ECLiPSe from a foreign language over I/O channels
like sockets, EXDR is the format you should use.  It is much easier to read/write
than ECLiPSe source syntax, and much easier (and more compact, efficient, etc)
than going through something like XML.  It is described here:
http://eclipse-clp.org/doc/embedding/embroot051.html

Andrea, would you be willing to share your PHP code, in particular for the
EXDR conversions?


-- Joachim
Received on Fri Feb 13 2009 - 06:40:19 CET

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