power-struct (original) (raw)

8.15

Defines a struct form that implements default values and construction in an ergonomic manner.

Examples:

> (require power-struct)
> (power-struct X (#:a 10 #:b 20) #:prefab)
> (make-X #:b 9)
'#s(X 10 9)
> (X-a (make-X #:b 9))
10

Otherwise functions as a completely regular struct. The only difference is that we use keywords instead of ids.

(power-struct name maybe-super (kw-default ...) rest ...)

Defines a power-struct. The kw-default takes a single keyword and a default value. If the keyword is missing during construction in make-name, then the default value is used. Normal struct accessors like name-id are generated.