A primitive procedure is a Scheme-callable procedure that is
implemented in C. Primitive procedures are created in MzScheme with
the function scheme_make_prim_w_arity, which takes a C
function pointer, the name of the primitive, and information about the
number of Scheme arguments that it takes; it returns a Scheme
procedure value.
The C function implementing the procedure must take two arguments: an
integer that specifies the number of arguments passed to the
procedure, and an array of Scheme_Object * arguments. The number
of arguments passed to the function will be checked using the arity
information.
(The arity information provided to scheme_make_prim_w_arity
is also for the Scheme arity proecdure.)
The function scheme_make_closed_prim_w_arity is similar to scheme_make_prim_w_arity, but it takes an additional void * argument; this argument is passed back to the C function when the closure is invoked. In this way, closure-like data from the C world can be associated with the primitive procedure.
When a primitive procedure is created, it is closed with repect to the current global environment. When the primitive procedure is invoked, this environment will be set as the current environment in the global variable scheme_current_env. Environment-specific settings, such as the current input and output ports, are available through this eonvironment's configuration record; the configuration record is obtained by calling scheme_env_config. For more information about thread environments and configuration records, see section 3.10.