Scheme 48 Manual | Contents | In Chapter: Mixing Scheme 48 and C
Previous: Accessing Scheme data from C | Next: Accessing Scheme data from C

Accessing Scheme data from C

The C header file scheme48.h provides access to Scheme 48 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 vector-length or the boolean returned by pair?, the corresponding C procedure returns a C value of the appropriate type, and not a s48_value. Predicates return 1 for true and 0 for false.

Constants

The following macros denote Scheme constants:

Converting values

The following macros and functions convert values between Scheme and C representations. The `extract' ones convert from Scheme to C and the `enter's go the other way.

S48_EXTRACT_BOOLEAN is false if its argument is #f and true otherwise. S48_ENTER_BOOLEAN is #f if its argument is zero and #t otherwise.

s48_extract_string and s48_extract_byte_vector return pointers to the actual storage used by the string or byte vector. These pointers are valid only until the next garbage collection.

The second argument to s48_enter_byte_vector is the length of byte vector.

s48_enter_integer() needs to allocate storage when its argument is too large to fit in a Scheme 48 fixnum. In cases where the number is known to fit within a fixnum (currently 30 bits including the sign), the following procedures can be used. These have the disadvantage of only having a limited range, but the advantage of never causing a garbage collection. S48_FIXNUM_P is a macro that true if its argument is a fixnum and false otherwise.

S48_TRUE_P is true if its argument is S48_TRUE and S48_FALSE_P is true if its argument is S48_FALSE.

An error is signalled if s48_extract_fixnum's argument is not a fixnum or if the argument to s48_enter_fixnum is less than S48_MIN_FIXNUM_VALUE or greater than S48_MAX_FIXNUM_VALUE (-229 and 229-1 in the current system).

C versions of Scheme procedures

The following macros and procedures are C versions of Scheme procedures. The names were derived by replacing `-' with `_', `?' with `_P', and dropping `!.

Previous: Accessing Scheme data from C | Next: Accessing Scheme data from C