Next: Multiple return values in Pre-Scheme, Previous: Pre-Scheme floating point operation, Up: More Pre-Scheme packages
The ps-record-types
structure defines the following special form
for introducing record types. Pre-Scheme record types are translated
to C as structs.
(define-record-type type type-descriptor (constructor argument-field-tag ...) (field-tag1 field-type-spec1 field-accessor1 [field-modifier1]) (field-tag2 field-type-spec2 field-accessor2 [field-modifier2]) ... (field-tagn field-type-specn field-accessorn [field-modifiern])Defines a record type. Type is mangled to the C struct type name (type-descriptor-name is unused unless running Pre-Scheme as Scheme). Constructor is defined to construct a record of the new type and initialize the fields argument-type-field ... with its arguments, respectively. If it cannot allocate a sufficient quantity of memory, constructor returns a null pointer. The initial values of fields that are not passed to the constructor are undefined. For each field fieldi specified,
- fieldi is specified to have the type field-type-speci;
- field-accessori is defined to be a procedure of one argument, a record of type type-name, that returns the value of the field fieldi of that record — its type is defined to be
(=> (
type-name)
field-type-speci)
; and- if present, field-modifieri is defined to be a procedure of two arguments, a record of type type-name and a value of type field-type-spec, that assigns the value of the field fieldi in its first argument to be the value of its second argument; its type is
(=> (
type-name field-type-spec) unit)
.Records must be deallocated explicitly when their lifetime has expired with
deallocate
.