2.8 Struct Descriptors
(require rebellion/type/struct) | package: rebellion |
procedure
(struct-descriptor? v) → boolean?
v : any/c
procedure
v : any/c
procedure
v : any/c
procedure
(struct-descriptor-type descriptor) → struct-type?
descriptor : initialized-struct-descriptor?
procedure
(struct-descriptor-super-type descriptor)
→ (or/c struct-info? #f) descriptor : struct-descriptor?
procedure
(struct-descriptor-name descriptor) → symbol?
descriptor : struct-descriptor?
procedure
(struct-descriptor-mutable-fields descriptor) → natural?
descriptor : struct-descriptor?
procedure
(struct-descriptor-immutable-fields descriptor) → natural?
descriptor : struct-descriptor?
procedure
(struct-descriptor-auto-fields descriptor) → natural?
descriptor : struct-descriptor?
procedure
(struct-descriptor-constructor descriptor) → procedure?
descriptor : struct-descriptor?
procedure
(struct-descriptor-predicate descriptor) → (-> any/c boolean?)
descriptor : struct-descriptor?
procedure
(struct-descriptor-accessor descriptor)
→ (-> any/c natural? any/c) descriptor : struct-descriptor?
procedure
(struct-descriptor-mutator descriptor)
→ (-> any/c natural? any/c void?) descriptor : struct-descriptor?
procedure
(make-struct-implementation #:name name [ #:mutable-fields mutable-fields #:immutable-fields immutable-fields #:auto-fields auto-fields #:auto-field-value auto-value #:super-type super-type #:property-maker prop-maker #:inspector inspector #:guard guard #:constructor-name constructor-name]) → initialized-struct-descriptor? name : symbol? mutable-fields : natural? = 0 immutable-fields : natural? = 0 auto-fields : natural? = 0 auto-value : any/c = #f super-type : (or/c struct-type? #f) = #f
prop-maker :
(-> uninitialized-struct-descriptor? (listof (cons/c struct-type-property? any/c))) = (λ (_) empty) inspector : (or/c inspector? 'prefab #f) = (current-inspector) guard : (or/c procedure? #f) = #f constructor-name : (or/c symbol? #f) = #f
Instead of fields defaulting to mutable and specifying a list of indices for immutable fields, this function accepts separate arguments for the number of mutable fields and the number of immutable fields. The created struct type puts all mutable fields before all immutable fields.
Structure type properties are created by the prop-maker function, which is called with the descriptor before it is initialized. This allows property values to refer to the functions associated with the descriptor, without requiring users of make-struct-implementation to create mutually recursive definitions.
The proc-spec argument is not supported directly. This argument is made obsolete by prop:procedure; instead of passing proc-spec callers should include a value for prop:procedure in the result of prop-maker.
> (define point-descriptor (make-struct-implementation #:name 'point #:immutable-fields 2)) > (define point (struct-descriptor-constructor point-descriptor)) > (point 1 2) #<point>