Next: , Previous: Structure Layout, Up: Structures


22.5.3 Structure Basics

This section describes the basic procedures for creating and accessing structures.

— Scheme Procedure: make-struct vtable tail-array-size [init ...]
— C Function: scm_make_struct (vtable, tail-array-size, init)

Create a new structure.

vtable must be a vtable structure (see Vtables).

tail-array-size must be a non-negative integer. If the layout specification indicated by vtable includes a tail-array, this is the number of elements allocated to that array.

The init... are optional arguments describing how successive fields of the structure should be initialized. Only fields with protection 'r' or 'w' can be initialized – fields of protection 's' are automatically initialized to point to the new structure itself; fields of protection 'o' can not be initialized by Scheme programs.

— Scheme Procedure: struct? x
— C Function: scm_struct_p (x)

Return #t iff obj is a structure object, else #f.

— Scheme Procedure: struct-ref structure n
— C Function: scm_struct_ref (structure, n)

Access the nth field of structure.

— Scheme Procedure: struct-set! structure n val
— C Function: scm_struct_set_x (structure, n, val)

Modify the nth field of structure to hold val.

If the field is of type 'p', then val can be an arbitrary value.

If the field is of type 'u', then val can only be a non-negative integer value small enough to fit in one machine word.