Next: Calling Scheme procedures from C, Previous: Dynamic loading of C modules, Up: C interface
The C header file scheme48.h provides access to Scheme48 data
structures. The type s48_value is used for Scheme values. When
the type of a value is known, such as the integer returned by the
Scheme procedure vector-length or the boolean returned by
pair, the corresponding C function returns a C value of the
appropriate type, not an s48_value. Predicates return 1
for true and 0 for false.
These C macros denote various Scheme constants.
S48_FALSEis the boolean false value, written in Scheme as#f.S48_TRUEis the boolean true value, or#t.S48_NULLis the empty list().S48_UNSPECIFICis a miscellaneous value returned by procedures that have no meaningful return value (accessed in Scheme48 by the nullary procedureunspecificin theutilstructure).S48_EOFis the end-of-file object (which the Scheme procedureeof-object?answers true for).S48_MAX_FIXNUM_VALUEis the maximum integer as alongthat can be represented in a Scheme48 fixnum.S48_MIN_FIXNUM_VALUEis similar, but the minimum integer.
These functions & macros convert values between their respective Scheme & C representations.
S48_EXTRACT_BOOLEANreturns0if boolean is#fand1otherwise.S48_ENTER_BOOLEANreturns the Scheme value#fif its argument is zero and#totherwise.
s48_extract_char&s48_enter_charconvert between Scheme characters and Cchars.
s48_extract_string&s48_extract_byte_vectorreturn pointers to the actual storage used by string or bytev. These pointers are valid only until the next garbage collection, however; see Interacting with the Scheme heap in C.s48_enter_string&s48_enter_byte_vectorallocate space on the Scheme48 heap for the given strings or byte vectors.s48_enter_stringcopies the data starting from the pointer it is given up to the first ASCIINULcharacter, whereass48_enter_byte_vectoris given the number of bytes to copy into the Scheme heap.
s48_extract_integerreturns a Clongthat represents the Scheme integer as input. If the Scheme integer is too large to be represented in a long, an exception is signalled. (The Scheme integer may be a fixnum or a bignum.)s48_enter_integerconverts back to Scheme integers, and it will never signal an exception.
s48_extract_double&s48_enter_doubleconvert between Scheme & C double-precision floating point representations.Of these,
s48_enter_string,s48_enter_byte_vector,s48_enter_integer, &s48_enter_doublemay cause the garbage collector to be invoked: the former two copy the string or byte vector onto the Scheme heap first,s48_enter_integermay need to allocate a bignum (since Clongs are wider than Scheme48 fixnums), and floats are heap-allocated in Scheme48.
S48_TRUE_Preturns true if object is the true constantS48_TRUEand false if otherwise.S48_FALSE_Preturns true if its argument is the false constantS48_FALSEand false if otherwise.
S48_FIXNUM_Pis the C predicate for Scheme48 fixnums, delimited in range byS48_MIN_FIXNUM_VALUE&S48_MAX_FIXNUM_VALUE.s48_extract_fixnumreturns the Clongrepresentation of the Scheme fixnum, ands48_enter_fixnumreturns the Scheme fixnum representation of the Clong. These are identical tos48_extract_integer&s48_enter_integer, except thats48_extract_fixnumwill never raise a range exception, buts48_enter_fixnummay, ands48_enter_fixnumwill never return a bignum; this is due to the fact that Clongs have a wider range than Scheme48 fixnums.
— C macro: s48_value S48_CAR (s48_value pair)
— C macro: s48_value S48_CDR (s48_value pair)
— C macro: void S48_SET_CAR (s48_value pair, s48_value object)
— C macro: void S48_SET_CDR (s48_value pair, s48_value object)
— C function (may GC): s48_value s48_cons (s48_value car, s48_value cdr)
— C function: s48_value s48_length (s48_value list)
— C macro: long S48_VECTOR_LENGTH (s48_value vector)
— C macro: s48_value S48_VECTOR_REF (s48_value vector, long index)
— C macro: void S48_VECTOR_SET (s48_value vector, long index, s48_value object)
— C function (may GC): s48_value s48_make_vector (long length, s48_value fill)
— C macro: long S48_STRING_LENGTH (s48_value string)
— C macro: char S48_STRING_REF (s48_value string, long index)
— C macro: void S48_STRING_SET (s48_value string, long index, char char)
— C function (may GC): s48_value s48_make_string (long length, char fill)
— C macro: s48_value S48_SYMBOL_TO_STRING (s48_value symbol)
— C macro: long S48_BYTE_VECTOR_LENGTH (s48_value bytev)
— C macro: char S48_BYTE_VECTOR_REF (s48_value bytev, long index)
— C macro: void S48_BYTE_VECTOR_SET (s48_value bytev, long index, char byte)
— C function (may GC): s48_value s48_make_byte_vector (long length)
C versions of miscellaneous Scheme procedures. The names were derived from their Scheme counterparts by replacing hyphens with underscores,
?suffixes with_P, and dropping!suffixes.