kw-make-struct
make/  kw
make/  fld
7.1

kw-make-struct

 (require kw-make-struct) package: kw-make-struct

source code: https://github.com/AlexKnauth/kw-make-struct

syntax

(make/kw struct-id field ...)

(make/kw struct-id field-pat ...)
 
field = expr
  | field-keyword expr
     
field-pat = pat
  | field-keyword pat
Like make from unstable/struct, except allowing keywords.

make/kw is also defined as a match expander.

Examples:
> (require kw-make-struct racket/match)
> (struct foo (a b c) #:transparent)
> (make/kw foo 'a 'b 'c)

(foo 'a 'b 'c)

> (make/kw foo #:a 'a #:b 'b #:c 'c)

(foo 'a 'b 'c)

> (make/kw foo #:a 'a 'b 'c)

(foo 'a 'b 'c)

> (make/kw foo #:c 'c 'a #:b 'b)

(foo 'a 'b 'c)

> (match (foo 'a 'b 'c)
    [(make/kw foo #:a a #:b b #:c c)
     (list a b c)])

'(a b c)

syntax

(make/fld struct-id [field-id expr] ...)

(make/fld struct-id [field-id pat] ...)
Creates an instance of struct-id, where [field-id expr] means that the field-id field will be the value of expr.

make/fld is also defined as a match expander.

Examples:
> (require kw-make-struct racket/match)
> (struct foo (a b c) #:transparent)
> (make/fld foo [a 'a] [b 'b] [c 'c])

(foo 'a 'b 'c)

> (make/fld foo [c 'c] [a 'a] [b 'b])

(foo 'a 'b 'c)

> (match (foo 'a 'b 'c)
    [(make/fld foo [a a] [b b] [c c])
     (list a b c)])

'(a b c)