(record builder) - Record builder

Library (record builder)

Record builder library. This library provides utilities to construct a record instance easily.

The following example shows how to use the make-record-buildermacro.

(define-record-type base
  (fields a b c))
(define-syntax base-builder
  (make-record-builder base ((a 'a) (c 'c symbol->string))))

(base-builder)
#\<base a='a b=#f c="c">

(define-record-type child
  (parent base)
  (fields d e f))
(define-syntax child-builder
  (make-record-builder child ((a 'b))))

(child-builder)
#\<child a='b b=#f c=#f d=#f e=#f f=#f>

Macro make-record-builder rtd (default ... )

Make a record builder macro transformer.

Default must be one of the following form:

(_field-name_ _value_)

(_field-name_ _value_ _converter_)

field-name must be a field name of the rtd. value is a default in case the builder didn't receive the field. The _converter_of the second form must be a procedure which accepts one argument. The result of this procedure will be used to instantisate the record. It will also apply the value.

The result of the macro transformer accepts the following forms:

(_field-name_ _value_) ...

(`from` _record-instance_) (_field_ _value_) ...

The from is an auxiliary macro bound in the (record builder). The value of from, record-instance, will be copied to the creating record.