This section describes the basic procedures for working with
make-struct creates a structure, and
struct-set! access write fields.
Create a new structure, with layout per the given vtable (see Vtables).
tail-size is the size of the tail array if vtable specifies a tail array. tail-size should be 0 when vtable doesn't specify a tail array.
The optional init... arguments are initial values for the fields of the structure (and the tail array). This is the only way to put values in read-only fields. If there are fewer init arguments than fields then the defaults are
#ffor a Scheme field (type
p) or 0 for an uninterpreted field (type
sself-reference fields, permission
oopaque fields, and the count field of a tail array are all ignored for the init arguments, ie. an argument is not consumed by such a field. An
sis always set to the structure itself, an
ois always set to
#for 0 (with the intention that C code will do something to it later), and the tail count is always the given tail-size.
For example,(define v (make-vtable "prpwpw")) (define s (make-struct v 0 123 "abc" 456)) (struct-ref s 0) ⇒ 123 (struct-ref s 1) ⇒ "abc"(define v (make-vtable "prpW")) (define s (make-struct v 6 "fixed field" 'x 'y)) (struct-ref s 0) ⇒ "fixed field" (struct-ref s 1) ⇒ 2 ;; tail size (struct-ref s 2) ⇒ x ;; tail array ... (struct-ref s 3) ⇒ y (struct-ref s 4) ⇒ #f
#tif obj is a structure, or
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, or if the field cannot be read because it's
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
Return the vtable used by struct.
This can be used to examine the layout of an unknown structure, see Vtable Contents.