
Next: Classes and Objects
Up: Structures
Previous: Structures
Structure values can only be created and updated with the constructor
and setter procedures created by define-struct, but structure
values are not opaque. These utility functions work on with all
structure 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 fields in the structure value v.
- (struct-ref v n)
returns the value of the nth field of the structure value
v. (The first field is index 0.) If v does not have an
nth field, 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 identifier of the form
struct:s. The remaining slots contain the
values of the fields of v. The struct->vector procedure
is intended for printing and debugging use.
The struct-type? predicate returns #t if its argument
is a structure type value or #f otherwise.
The struct-setter-procedure? predicate returns #t
if its argument is a setter procedure generated by define-struct
or #f otherwise.
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 fields are all
equal?.
PLT