[racket] Access scheme library from C

From: Daniel Langner (s8572327 at gmail.com)
Date: Mon Dec 2 17:24:46 EST 2013

Thanks for the reply. This is what I got so far:

It doesn't segfault or anything. I'm not quite sure if I'm just being 
lucky here. :)

On 02/12/13 23:03, Matthew Flatt wrote:
> The easiest approach is often to put Racket in its own OS-level thread,
> where scheme_main_setup() is given a function that receives evaluations
> requests and sends back results.
> Currently, I don't think it's possible to call into Racket, completely
> leave, and call back in the way you suggest. You might imagine calling
> scheme_set_stack_base() on each entry to reset the start of the stack
> traversal on each entry, but that would create various problems with,
> for example, Racket continuations or threads that are captured/started
> in one scheme_set_stack_base() and applied/resumed in another.
> At Mon, 02 Dec 2013 17:12:35 +0100, Daniel Langner wrote:
>> Hello,
>> I want to embed the racket interpreter to create a C interface for a
>> certain r6rs scheme library. It comprises diverse functions which return
>> complex scheme objects. These, in turn, may be passed to other functions
>> within the library (and therefore shouldn't be gc'ed along the way).
>> I got it so far that I call scheme_main_setup, passing along my run
>> function which loads the library into the scheme environment and does
>> the actual scheme calls. This approach, however, isn't suitable for what
>> I want. When run returns, all is gone and gets garbage collected (I think).
>> I'd rather have a typical interface with an initialization function
>> (that loads the environment and returns normally), some wrapper
>> functions (which call scheme_dynamic_require and scheme_apply), and a
>> destructor function.
>> Probably I'd have to use scheme_set_stack_base rather than
>> scheme_main_setup. Obviously I would want to reuse the environment
>> throughout all calls. There hopefully is a way to prevent the garbage
>> collector from collecting it, and also the other scheme objects which my
>> library returns.
>> My question is: is this feasible? How would I go about it? Thanks for
>> your help!
>> Regards,
>> Daniel
>> ____________________
>>    Racket Users list:
>>    http://lists.racket-lang.org/users

Posted on the users mailing list.