This section describes the basic procedures for working with structures.
make-struct/no-tail creates a structure, and
struct-set! access its fields.
Create a new structure, with layout per the given vtable (see Vtables).
The optional init… arguments are initial values for the
fields of the structure. This is the only way to
put values in read-only fields. If there are fewer init
arguments than fields then the defaults are
#f for a Scheme
p) or 0 for an unboxed field (type
The name is a bit strange, we admit. The reason for it is that Guile
used to have a
make-struct that took an additional argument;
while we deprecate that old interface,
make-struct/no-tail is the
new name for this functionality.
(define v (make-vtable "pwpwpw")) (define s (make-struct/no-tail v 123 "abc" 456)) (struct-ref s 0) ⇒ 123 (struct-ref s 1) ⇒ "abc"
There are a few ways to make structures from C.
takes a list,
scm_c_make_struct takes variable arguments
terminated with SCM_UNDEFINED, and
scm_c_make_structv takes a
For all of these, tail_size should be zero (as a SCM value).
#t if obj is a structure, or
#f if not.
Return the contents of field number n in struct. The first field is number 0.
An error is thrown if n is out of range.
Set field number n in struct to value. The first field is number 0.
An error is thrown if n is out of range, or if the field cannot
be written because it’s
Unboxed fields (those with type
u) need to be accessed with
struct-set!, except that these may
only be used on unboxed fields.
struct-ref/unboxed will always
return a positive integer. Likewise,
an unsigned integer as the value argument, and will signal an
Return the vtable that describes struct.
The vtable is effectively the type of the structure. See Vtable Contents, for more on vtables.