On this page:
adjust-struct-info
8.16.0.4

20 Compile-time Struct Info🔗ℹ

 (require scramble/struct-info) package: scramble-lib

procedure

(adjust-struct-info base-info 
  [#:constructor constructor-id 
  #:match-expander match-expander]) 
  struct-info?
  base-info : struct-info?
  constructor-id : (or/c identifier? #f) = #f
  match-expander : (or/c #f (-> syntax? syntax?)) = #f
Produces a struct-info record like base-info but with new behavior as a constructor and match pattern. That is, if name is bound to the result using define-syntax etc, and if constructor-id is not #f, then a use of name as an expression is redirected to constructor-id; and if match-expander is not #f, then a use of name in a match pattern is expanded using match-expander.

If base-info is an instance of a struct type with any of the following properties, the result has the same properties with the same values: prop:struct-auto-info, prop:struct-field-info. Other properties of base-info are not preserved.

The following example defines a point struct and then replaces point with an adjusted struct info record that adds a contract and makes one of the constructor arguments optional:
> (module point racket/base
    (provide (struct-out point))
    (struct point (x y) #:transparent))
> (module point-adjusted racket/base
    (require (for-syntax racket/base scramble/struct-info)
             racket/contract
             (rename-in 'point [point orig-point]))
    (define (make-point x [y 0]) (orig-point x y))
    (define-module-boundary-contract checked-make-point make-point
      (->* [real?] [real?] point?)
      #:name-for-blame point)
    (define-syntax point
      (adjust-struct-info (syntax-local-value #'orig-point)
                          #:constructor #'checked-make-point))
    (provide (struct-out point)))
> (require 'point-adjusted)
> (point 1 2)

(point 1 2)

> (point 3)

(point 3 0)

> (point 'hello 'goodbye)

point: contract violation

  expected: real?

  given: 'hello

  in: the 1st argument of

      (->* (real?) (real?) point?)

  contract from: 'point-adjusted

  blaming: top-level

   (assuming the contract is correct)

  at: eval:2:0

> (struct point3 point (z) #:transparent)
> (point3 1 2 3)

(point3 1 2 3)