Next: Optional Arguments, Previous: Lambda, Up: Procedures and Macros
Procedures written in C can be registered for use from Scheme,
provided they take only arguments of type SCM and return
SCM values. scm_c_define_gsubr is likely to be the most
useful mechanism, combining the process of registration
(scm_c_make_gsubr) and definition (scm_define).
Register a C procedure FCN as a “subr” — a primitive subroutine that can be called from Scheme. It will be associated with the given name but no environment binding will be created. The arguments req, opt and rst specify the number of required, optional and “rest” arguments respectively. The total number of these arguments should match the actual number of arguments to fcn. The number of rest arguments should be 0 or 1.
scm_c_make_gsubrreturns a value of typeSCMwhich is a “handle” for the procedure.
Register a C procedure FCN, as for
scm_c_make_gsubrabove, and additionally create a top-level Scheme binding for the procedure in the “current environment” usingscm_define.scm_c_define_gsubrreturns a handle for the procedure in the same way asscm_c_make_gsubr, which is usually not further required.
scm_c_make_gsubr and scm_c_define_gsubr automatically
use scm_c_make_subr and also scm_makcclo if necessary.
It is advisable to use the gsubr variants since they provide a
slightly higher-level abstraction of the Guile implementation.