1 Language Model
2 Syntactic Forms
3 Datatypes
4 Structures
5 Classes and Objects
6 Units
7 Contracts
8 Pattern Matching
9 Control Flow
10 Concurrency
11 Macros
12 Input and Output
13 Reflection and Security
14 Operating System
15 Memory Management
16 Running PLT Scheme
Bibliography
Index
On this page:
struct-info?
checked-struct-info?
make-struct-info
extract-struct-info
struct: struct-info
Version: 4.0.2

 

4.6 Structure Type Transformer Binding

The define-struct form binds the name of a structure type as a transformer binding that records the other identifiers bound to the structure type, the constructor procedure, the predicate procedure, and the field accessor and mutator procedures. This information can be used during the expansion of other expressions via syntax-local-value.

For example, the define-struct variant for subtypes uses the base type name t to find the variable struct:t containing the base type’s descriptor; it also folds the field accessor and mutator information for the base type into the information for the subtype. As another example, the match form uses a type name to find the predicates and field accessors for the structure type. The struct form in an imported signature for unit causes the unit transformer to generate information about imported structure types, so that match and subtyping define-struct forms work within the unit.

The expansion-time information for a structure type is represented either as a structure that encapsulates a procedure that takes no arguments and returns a list of six element, or it can be represented directly as a list of six elements (of the same sort that the encapsulated procedure must return):

Use struct-info? to recognize both forms of information, and use extract-struct-info to obtain a list from either representation. Use make-struct-info to encapsulate a procedure that represents structure type information.

The implementor of a syntactic form can expect users of the form to know what kind of information is available about a structure type. For example, the match implementation works with structure information containing an incomplete set of accessor bindings, because the user is assumed to know what information is available in the context of the match expression. In particular, the match expression can appear in a unit form with an imported structure type, in which case the user is expected to know the set of fields that are listed in the signature for the structure type.

 (require scheme/struct-info)

The bindings documented in this section are provided by the scheme/struct-info library, not scheme/base or scheme.

(struct-info? v)  boolean?

  v : any/c

Returns #t if v is either a six-element list with the correct shape for representing structure-type information, or a procedure encapsulated by make-struct-info.

(checked-struct-info? v)  boolean?

  v : any/c

Returns #t if v is a procedure encapsulated by make-struct-info and produced by define-struct, but only when no parent type is specified or the parent type is also specified through a transformer binding to such a value).

(make-struct-info thunk)  struct-info?

  thunk : (-> (and/c struct-info? list?))

Encapsulates a thunk that returns structure-type information in list form.

(extract-struct-info v)  (and/c struct-info? list?)

  v : struct-info?

Extracts the list form of the structure type information represented by v.

struct:struct-info : struct-type?

The structure type descriptor for the structure type returned by make-struct-info. This structure type descriptor is mostly useful for creating structure subtypes. The structure type includes a guard that checks an instance’s first field in the same way as make-struct-info.