[gambit-list] C Embedding question
Marc Feeley
feeley at iro.umontreal.ca
Thu Jan 29 07:54:44 EST 2009
On 29-Jan-09, at 1:44 AM, Alex Ryu wrote:
> Hello
> I would like to do something similar to the following within my C
> program:
> *****************
> char* condition = "(2 < 4) & (3 > 7");
> int boole;
> ...
> boole = evaluate(condition);
> *****************
> where evaluate is a scheme function already written and compiled by
> gsc. Most of the documentation I have seen relates more to the
> reversed situation - calling C functions from scheme. I have taken a
> look at the client example program in the tests directory, but it is
> not clear to me exactly how the string is treated by scheme - ie, in
> what form it is going to be, if that makes any sense. Obviously I
> would prefer it as a list of some sort, but I don't know if that's
> possible. I am using Linux and gcc 4, if that makes a difference.
> Thanks for your time
> Alex
The example code in tests/client.c and tests/server.scm is very close
to what you want. One difference is that you want the function to
return a boolean. The other difference is that in your example you
are using an infix expression. Is this really what you want? The
code in tests/server.scm uses Scheme's normal prefix syntax. If you
really want infix then you could change the eval-string function in
tests/server.scm to be
(c-define (evaluate str) (char-string) bool "evaluate" "extern"
(catch-all-errors
(lambda () (eval (read-from-string (string-append "\\" str
";"))))))
This will use Gambit's SIX parser (Scheme infix syntax extension).
This is untested code.
Marc
More information about the Gambit-list
mailing list