#lang scribble/doc @(require "utils.ss") @title{Miscellaneous Utilities} The @cppi{MZSCHEME_VERSION} preprocessor macro is defined as a string describing the version of Scheme. The @cppi{MZSCHEME_VERSION_MAJOR} and @cppi{MZSCHEME_VERSION_MINOR} macros are defined as the major and minor version numbers, respectively. @function[(int scheme_eq [Scheme_Object* obj1] [Scheme_Object* obj2])]{ Returns 1 if the Scheme values are @scheme[eq?].} @function[(int scheme_eqv [Scheme_Object* obj1] [Scheme_Object* obj2])]{ Returns 1 if the Scheme values are @scheme[eqv?].} @function[(int scheme_equal [Scheme_Object* obj1] [Scheme_Object* obj2])]{ Returns 1 if the Scheme values are @scheme[equal?].} @function[(int scheme_recur_equal [Scheme_Object* obj1] [Scheme_Object* obj2] [void* cycle_data])]{ Like @cpp{scheme_equal}, but accepts an extra value for cycle tracking. This procedure is meant to be called by a procedure installed with @cpp{scheme_set_type_equality}.} Returns 1 if the Scheme values are @scheme[equal?].} @function[(long scheme_equal_hash_key [Scheme_Object* obj])]{ Returns the primary @scheme[equal?]-hash key for \var{obj}.} @function[(long scheme_equal_hash_key2 [Scheme_Object* obj])]{ Returns the secondary @scheme[equal?]-hash key for \var{obj}.} @function[(long scheme_recur_equal_hash_key [Scheme_Object* obj] [void* cycle_data])]{ Like @cpp{scheme_equal_hash_key}, but accepts an extra value for cycle tracking. This procedure is meant to be called by a hasing procedure installed with @cpp{scheme_set_type_equality}.} Returns the primary @scheme[equal?]-hash key for \var{obj}.} @function[(long scheme_recur_equal_hash_key2 [Scheme_Object* obj] [void* cycle_data])]{ Like @cpp{scheme_equal_hash_key2}, but accepts an extra value for cycle tracking. This procedure is meant to be called by a secondary hashing procedure installed with @cpp{scheme_set_type_equality}.} @function[(long scheme_build_list [int c] [Scheme_Object** elems])]{ Creates and returns a list of length @var{c} with the elements @var{elems}.} @function[(int scheme_list_length [Scheme_Object* list])]{ Returns the length of the list. If @var{list} is not a proper list, then the last @scheme[cdr] counts as an item. If there is a cycle in @var{list} (involving only @scheme[cdr]s), this procedure will not terminate.} @function[(int scheme_proper_list_length [Scheme_Object* list])]{ Returns the length of the list, or -1 if it is not a proper list. If there is a cycle in @var{list} (involving only @scheme[cdr]s), this procedure returns -1.} @function[(Scheme_Object* scheme_car [Scheme_Object* pair])]{ Returns the @scheme[car] of the pair.} @function[(Scheme_Object* scheme_cdr [Scheme_Object* pair])]{ Returns the @scheme[cdr] of the pair.} @function[(Scheme_Object* scheme_cadr [Scheme_Object* pair])]{ Returns the @scheme[cadr] of the pair.} @function[(Scheme_Object* scheme_caddr [Scheme_Object* pair])]{ Returns the @scheme[caddr] of the pair.} @function[(Scheme_Object* scheme_vector_to_list [Scheme_Object* vec])]{ Creates a list with the same elements as the given vector.} @function[(Scheme_Object* scheme_list_to_vector [Scheme_Object* list])]{ Creates a vector with the same elements as the given list.} @function[(Scheme_Object* scheme_append [Scheme_Object* lstx] [Scheme_Object* lsty])]{ Non-destructively appends the given lists.} @function[(Scheme_Object* scheme_unbox [Scheme_Object* obj])]{ Returns the contents of the given box.} @function[(void scheme_set_box [Scheme_Object* b] [Scheme_Object* v])]{ Sets the contents of the given box.} @function[(Scheme_Object* scheme_load [char* file])]{ Loads the specified Scheme file, returning the value of the last expression loaded, or @cpp{NULL} if the load fails.} @function[(Scheme_Object* scheme_load_extension [char* filename])]{ Loads the specified Scheme extension file, returning the value provided by the extension's initialization function.} @function[(Scheme_Hash_Table* scheme_make_hash_table [int type])]{ Creates a hash table. The @var{type} argument must be either @cppi{SCHEME_hash_ptr} or @cppi{SCHEME_hash_string}, which determines how keys are compared (unless the hash and compare functions are modified in the hash table record; see below). A @cpp{SCHEME_hash_ptr} table hashes on a key's pointer address, while @cpp{SCHEME_hash_string} uses a key as a @cpp{char*} and hashes on the null-terminated string content. Since a hash table created with @cpp{SCHEME_hash_string} (instead of @cpp{SCHEME_hash_ptr}) does not use a key as a Scheme value, it cannot be used from Scheme code. Although the hash table interface uses the type @cpp{Scheme_Object*} for both keys and values, the table functions never inspect values, and they inspect keys only for @cpp{SCHEME_hash_string} hashing. Thus, the actual types of the values (and keys, for @cpp{SCHEME_hash_ptr} tables) can be anything. The public portion of the @cppi{Scheme_Hash_Table} type is defined roughly as follows: @verbatim[#<= number of mapped keys */ Scheme_Bucket **buckets; void (*make_hash_indices)(void *v, long *h1, long *h2); int (*compare)(void *v1, void *v2); /* ... */ } Scheme_Bucket_Table; EOS ] The @cpp{make_hash_indices} and @cpp{compare} functions are used as for hash tables. Note that @cppi{SCHEME_hash_weak_ptr} supplied as the initial type makes keys weak even if the hash and comparison functions are changed. See @cpp{scheme_bucket_from_table} for information on buckets.} @function[(void scheme_add_to_table [Scheme_Bucket_Table* table] [const-char* key] [void* val] [int const])]{ Sets the current value for @var{key} in @var{table} to @var{val}. If @var{const} is non-zero, the value for @var{key} must never be changed.} @function[(void scheme_change_in_table [Scheme_Bucket_Table* table] [const-char* key] [void* val])]{ Sets the current value for @var{key} in @var{table} to @var{val}, but only if @var{key} is already mapped in the table.} @function[(void* scheme_lookup_in_table [Scheme_Bucket_Table* table] [const-char* key])]{ Returns the current value for @var{key} in @var{table}, or @cpp{NULL} if @var{key} has no value.} @function[(Scheme_Bucket* scheme_bucket_from_table [Scheme_Bucket_Table* table] [const-char* key])]{ Returns the bucket for @var{key} in @var{table}. The @cppi{Scheme_Bucket} structure is defined as: @verbatim[#<