Previous: Memory allocation and garbage collection, Up: GH
Many of the Scheme primitives are available in the gh_
interface; they take and return objects of type SCM, and one could
basically use them to write C code that mimics Scheme code.
I will list these routines here without much explanation, since what
they do is the same as documented in R5RS. But I will point out that when a procedure takes a
variable number of arguments (such as gh_list), you should pass
the constant SCM_UNDEFINED from C to signify the end of the list.
Corresponds to the Scheme
(define name val): it binds a value to the given name (which is a C string). Returns the new object.
These correspond to the Scheme
(cons a b)and(list l0 l1 ...)procedures. Note thatgh_list()is a C macro that invokesscm_list_n().
... — Function: SCM gh_c[ad][ad][ad][ad]r (SCM obj)
These correspond to the Scheme
(caadar ls)procedures etc ...
Modifies the CAR of pair to be value. This is equivalent to the Scheme procedure
(set-car! ...).
Modifies the CDR of pair to be value. This is equivalent to the Scheme procedure
(set-cdr! ...).
gh_append()takes args, which is a list of lists(list1 list2 ...), and returns a list containing all the elements of the individual lists.A typical invocation of
gh_append()to append 5 lists together would begh_append(gh_list(l1, l2, l3, l4, l5, SCM_UNDEFINED));The functions
gh_append2(),gh_append2(),gh_append3()andgh_append4()are convenience routines to make it easier for C programs to form the list of lists that goes as an argument togh_append().
Returns a new list that has the same elements as ls but in the reverse order. Note that this is implemented as a macro which calls
scm_reverse().
These functions return the first sublist of ls whose CAR is x. They correspond to
(memq x ls),(memv x ls)and(member x ls), and hence use (respectively)eq?,eqv?andequal?to do comparisons.If x does not appear in ls, the value
SCM_BOOL_F(not the empty list) is returned.Note that these functions are implemented as macros which call
scm_memq(),scm_memv()andscm_member()respectively.
These functions search an association list (list of pairs) alist for the first pair whose CAR is x, and they return that pair.
If no pair in alist has x as its CAR, the value
SCM_BOOL_F(not the empty list) is returned.Note that these functions are implemented as macros which call
scm_assq(),scm_assv()andscm_assoc()respectively.
These correspond to the Scheme
(make-vector n fill),(vector a b c ...)(vector-ref v i)(vector-set v i value)(vector-length v)(list->vector ls)procedures.The correspondence is not perfect for
gh_vector: this routine takes a list ls instead of the individual list elements, thus making it identical togh_list_to_vector.There is also a difference in gh_vector_length: the value returned is a C
unsigned longinstead of an SCM object.
Call the Scheme procedure proc, with the elements of args as arguments. args must be a proper list.
Call the Scheme procedure proc with no arguments (
gh_call0), one argument (gh_call1), and so on. You can get the same effect by wrapping the arguments up into a list, and callinggh_apply; Guile provides these functions for convenience.
Corresponds to the Scheme
catchandthrowprocedures, which in Guile are provided as primitives.
These correspond to the Scheme
eq?,eqv?andequal?predicates.
For now I just include Tim Pierce's comments from the gh_data.c file; it should be organized into a documentation of the two functions here.
/* Data lookups between C and Scheme
Look up a symbol with a given name, and return the object to which
it is bound. gh_lookup examines the Guile top level, and
gh_module_lookup checks the module name space specified by the
`vec' argument.
The return value is the Scheme object to which SNAME is bound, or
SCM_UNDEFINED if SNAME is not bound in the given context. [FIXME:
should this be SCM_UNSPECIFIED? Can a symbol ever legitimately be
bound to SCM_UNDEFINED or SCM_UNSPECIFIED? What is the difference?
-twp] */