Next: Classes and Objects
Up: Structures
Previous: Creating Subtypes
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 v) returns
the number of field values in the structure v.
- (struct-ref v n)
returns the value of the nth field of the structure
v. (The first field is index 0.) If v does not have an
nth field value, the exn:application:range:struct exception is raised.
- (struct->vector v)
converts the structure value v 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 v. 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-selector-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.
PLT