[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

a better way of calling Prolog from C

Subject: a better way of calling Prolog from C
Date: Fri, 27 Oct 2000 13:31:14 +0100
User-agent: Mutt/1.3.10i

I think there are two problems with the currently recommended way of
calling Prolog from C:

(1) As I said in my previous message, most of the Mk_* functions
consume non-renewable resources when you call them from the top level
C code. You run out of global stack after a while.

(2) It's quite complicated when you only want something simple.

So I suggest an alternative API like this:

    char *output;
    call_prolog("reverse", "cC", "input", &output);

Here 'c' means an input argument created with Mk_Codes, and 'C' means
an output argument read with Rd_Codes. This example causes the Prolog
goal reverse("input",Output) to be called. The first solution is taken
and the output is copied into a newly allocated C string.

I have made a prototype implementation using a callback: C calls
Prolog, and Prolog then calls C again to get the arguments. This
program tests the implementation by reversing 1000000 strings,
apparently without leaking resources.


 - Is there a better way of implementing this?
 - Should a function like call_prolog() be provided by GNU Prolog?
 - Should call_prolog() be extended to cope with multiple solutions,
   or even nested queries?


Attachment: callp.c
Description: Text document

Description: Perl program

reply via email to

[Prev in Thread] Current Thread [Next in Thread]