[plt-scheme] Adding primitive c procedure

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Fri Jul 25 07:44:14 EDT 2008

Noel Welsh <noelwelsh at gmail.com <mailto:noelwelsh at gmail.com>> wrote:
 > To add a new C function to MzScheme the FFI is much simpler to use:
 > http://docs.plt-scheme.org/foreign/index.html

Erlend Lorentzen wrote:
> I should have mentioned that I need MzScheme to be a drop-in 
> replacement for embedded Guile in a large (85,000 LOC) C++ application 
> with 100's of scheme scripts. My plan is to use the existing structure 
> of the application (as far as it's possible) and translate the current 
> Guile specific C functions to MzScheme versions of these functions, 
> and making as few changes as possible to the scheme scripts. Is this a 
> sane way to approach this? Could I use FFI in this case or would that 
> require an enormous restructuring?
Without knowing the exact details I'd recommend at least giving the FFI 
a try.
If you can make it to work, you'll save huge amounts of time both in the 
and long run.

"Simply" write your functions in C, compile them to a shared library, and
then load them in Scheme with the FFI. The FFI takes care of the tedious
stuff (converting between Scheme and C values, constructing
C structures etc).

One advantage of the FFI is that you won't run into problems when mzscheme
is updated.

To avoid potential confusion I'll just mention that the new FFI is the 
one scheme/foreign.

Jens Axel Søgaard

Posted on the users mailing list.