-
Notifications
You must be signed in to change notification settings - Fork 16
/
custom-write.scrbl
56 lines (47 loc) · 2.09 KB
/
custom-write.scrbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#lang scribble/manual
@(require (for-label racket/base
racket/contract/base
racket/math
racket/pretty
racket/struct
rebellion/custom-write
rebellion/type/struct
rebellion/type/tuple)
(submod rebellion/private/scribble-evaluator-factory doc)
(submod rebellion/private/scribble-cross-document-tech doc)
scribble/example)
@(define make-evaluator
(make-module-sharing-evaluator-factory
#:public (list 'racket/pretty
'rebellion/custom-write
'rebellion/type/struct
'rebellion/type/tuple)
#:private (list 'racket/base)))
@title{Custom Write Implementations}
@defmodule[rebellion/custom-write]
A @deftech{custom write implementation} is a function that prints values and is
suitable for use with @racket[prop:custom-write]. Custom write implementations
must satisfy the @racket[custom-write-function/c] contract.
@defthing[custom-write-function/c chaperone-contract?
#:value (-> any/c output-port? custom-write-mode/c void?)]{
A @tech/reference{contract} describing functions suitable for use with @racket[
prop:custom-write].}
@defthing[custom-write-mode/c flat-contract?
#:value (or/c boolean? 0 1)]{
A @tech/reference{contract} describing the @racket[_mode] argument to functions
matching @racket[custom-write-function/c]. See @racket[gen:custom-write] for
details.}
@defproc[(make-named-object-custom-write
[type-name symbol?]
[#:name-getter get-name (-> any/c (or/c symbol? #false)) object-name])
custom-write-function/c]{
Constructs a @tech{custom write implementation} that prints values as opaque,
unreadable, named objects, similar to the way functions are printed.
@(examples
#:eval (make-evaluator) #:once
(struct person (name)
#:property prop:object-name (struct-field-index name)
#:property prop:custom-write (make-named-object-custom-write 'person))
(person 'alyssa)
(person 'jared)
(person #false))}