Node:Defining new Scheme procedures in C, Next:Converting data between C and Scheme, Previous:Executing Scheme code, Up:GH
The real interface between C and Scheme comes when you can write new Scheme procedures in C. This is done through the routine
|SCM gh_new_procedure (char *proc_name, SCM (*fn)(), int n_required_args, int n_optional_args, int restp)||Libguile high|
When the restp parameter is 1, the procedure takes a final argument: a list of remaining parameters.
The C function fn should have the form
Rationale: this is the correct way to define new Scheme procedures in C. The ugly mess of arguments is required because of how C handles procedures with variable numbers of arguments.
Note: what about documentation strings?
There are several important considerations to be made when writing the C
First of all the C routine has to return type
Second, all arguments passed to the C function will be of type
Third: the C routine is now subject to Scheme flow control, which means that it could be interrupted at any point, and then reentered. This means that you have to be very careful with operations such as allocating memory, modifying static data ...
Fourth: to get around the latter issue, you can use
|These macros disable and re-enable Scheme's flow control. They|