Next: Classes and Objects Up: Structures Previous: Creating Subtypes

# Structure Utilities

Structures can only be created and changed with the constructor and setter procedures created by `struct`, but structures are not opaque. These utility procedures work with all structure instance values:

- `(struct? v)` returns `#t` if v was created by any `make-`s or `#f` otherwise. All other built-in predicates return `#f` for values constructed by a `make-`s.
- `(struct-length struct)` returns the number of field values in the structure struct.
- `(struct-ref struct k)` returns the value of the kth field of the structure struct. (The first field is index 0.) If struct does not have an kth field value, the `exn:application:mismatch` exception is raised.
- `(struct->vector struct)` converts the structure value struct to a vector. The first slot of the result vector contains an symbol of the form `struct:s`. The remaining slots contain the field values of struct. The `struct->vector` procedure is intended for printing and debugging use.

Two structure values are `eqv?` if and only if they are `eq?`. Two structure values are `equal?` if they have the same structure type and their corresponding field values are all `equal?`.

Each kind of value returned by `struct` has a recognizing predicate:

- `(struct-type? v)` returns `#t` if v is a structure type descriptor value, `#f` otherwise.
- `(struct-constructor-procedure? v)` returns `#t` if v is a constructor procedure generated by `struct`, `#f` otherwise.
- `(struct-predicate-procedure? v)` returns `#t` if v is a predicate procedure generated by `struct`, `#f` otherwise.
- `(struct-getter-procedure? v)` returns `#t` if v is a selector procedure generated by `struct`, `#f` otherwise.
- `(struct-setter-procedure? v)` returns `#t` if v is a setter procedure generated by `struct`, `#f` otherwise.

Next: Classes and Objects Up: Structures Previous: Creating Subtypes