On this page:
custom-write-function/  c
custom-write-mode/  c
make-named-object-custom-write
make-constant-custom-write
2.1 Struct Custom Write Implementations
make-struct-constructor-style-custom-write
2.2 Tuple Custom Write Implementations
make-tuple-constructor-style-custom-write
make-tuple-named-object-custom-write
7.3

2 Custom Write Implementations

 (require rebellion/custom-write) package: rebellion

A custom write implementation is a function that prints values and is suitable for use with prop:custom-write. Custom write implementations must satisfy the custom-write-function/c contract.

A contract describing functions suitable for use with prop:custom-write.

A contract describing the mode argument to functions matching custom-write-function/c. See gen:custom-write for details.

procedure

(make-named-object-custom-write type-name 
  [#:name-getter get-name]) 
  custom-write-function/c
  type-name : symbol?
  get-name : (-> any/c (or/c symbol? #f)) = object-name
Constructs a custom write implementation that prints values as opaque, unreadable, named objects, similar to the way functions are printed.

Examples:
> (struct person (name)
    #:property prop:object-name (struct-field-index name)
    #:property prop:custom-write (make-named-object-custom-write 'person))
> (person 'alyssa)

#<person:alyssa>

> (person 'jared)

#<person:jared>

> (person #f)

#<person>

Constructs a custom write implementation that prints all values as the same opaque constant value named name, similar to the way eof prints.

Examples:
> (struct widget ()
    #:property prop:custom-write (make-constant-custom-write 'widget))
> (widget)

#<widget>

2.1 Struct Custom Write Implementations

 (require rebellion/custom-write/struct)
  package: rebellion

Constructs a custom write implementation that prints instances of the structure type described by descriptor in a manner similar to the way that make-constructor-style-printer prints values.

Examples:
> (define (make-props descriptor)
    (define custom-write
      (make-struct-constructor-style-custom-write descriptor))
    (list (cons prop:custom-write custom-write)))
> (define point-descriptor
    (make-struct-type/descriptor #:name 'point
                                 #:immutable-fields 2
                                 #:property-maker make-props))
> (define point (struct-descriptor-constructor point-descriptor))
> (point 1 2)

(point 1 2)

> (parameterize ([pretty-print-columns 10])
    (pretty-print (point 100000000000000 200000000000000)))

(point

 100000000000000

 200000000000000)

2.2 Tuple Custom Write Implementations

 (require rebellion/custom-write/tuple)
  package: rebellion

Constructs a custom write implementation that prints instances of the tuple type described by descriptor in a manner similar to the way that make-constructor-style-printer prints values.

Examples:
> (define-tuple-type point (x y)
    #:property-maker
    (λ (descriptor)
      (define custom-write
        (make-tuple-constructor-style-custom-write descriptor))
      (list (cons prop:custom-write custom-write))))
> (point 1 2)

(point 1 2)

> (parameterize ([pretty-print-columns 10])
    (pretty-print (point 100000000000000 200000000000000)))

(point

 100000000000000

 200000000000000)

procedure

(make-tuple-named-object-custom-write descriptor 
  [#:name-field name-field]) 
  custom-write-function/c
  descriptor : tuple-descriptor?
  name-field : (or/c natural? #f) = #f
Constructs a custom write implementation that prints instances of the tuple type described by descriptor in a manner similar to the way that make-named-object-custom-write prints values. If name-field is provided, it must refer to a field in the tuple type that will contain each instance’s name. Otherwise, object-name is used to extract the name of each instance.

Examples:
> (define-tuple-type person (name)
    #:property-maker
    (λ (descriptor)
      (list (cons prop:object-name 0)
            (cons prop:custom-write
                  (make-tuple-named-object-custom-write descriptor)))))
> (person 'alyssa)

#<person:alyssa>

> (person 'jared)

#<person:jared>

> (person #f)

#<person>