Updated scribble docs for make-constructor-style-printer

It should be using gen:custom-write rather than prop:custom-write.
This commit is contained in:
Leif Andersen 2016-04-25 19:18:11 -04:00
parent 5cc030e2ad
commit f549724e36
2 changed files with 35 additions and 16 deletions

View File

@ -1,5 +1,5 @@
#lang scribble/doc
@(require "mz.rkt")
@(require "mz.rkt" (for-label racket/struct-info))
@title{Printer Extension}
@ -77,6 +77,22 @@ so that graph and cycle structure can be represented.
(vector-set! (tuple-ref t) 0 t)
(write t))
]
This function is often used in conjunction with @racket[make-constructor-style-printer].
@examples[
(eval:no-prompt (require racket/struct))
(eval:no-prompt
(struct point (x y)
#:methods gen:custom-write
[(define write-proc
(make-constructor-style-printer
(lambda (obj) 'point)
(lambda (obj) (list (point-x obj) (point-y obj)))))]))
(print (point 1 2))
(write (point 1 2))]
}
@defthing[prop:custom-write struct-type-property?]{

View File

@ -1,5 +1,5 @@
#lang scribble/doc
@(require "mz.rkt" (for-label racket/struct-info))
@(require "mz.rkt" (for-label racket/struct))
@(define struct-eval (make-base-eval))
@(define struct-copy-eval (make-base-eval))
@ -616,24 +616,27 @@ See @racket[make-prefab-struct] for a description of valid key shapes.}
[get-contents (-> any/c sequence?)])
(-> any/c output-port? (or/c #t #f 0 1) void?)]{
Produces a function suitable as a value for @racket[prop:custom-write]. The
function prints values in ``constructor style.'' When the value is
@racket[print]ed as an expression, it is shown as an application of the
constructor (as returned by @racket[get-constructor]) to the contents (as
returned by @racket[get-contents]). When given to @racket[write], it is shown as
an unreadable value with the constructor separated from the contents by a colon.
Produces a function suitable as a value for
@racket[gen:custom-write] or @racket[prop:custom-write].
The function prints values in ``constructor style.'' When
the value is @racket[print]ed as an expression, it is shown
as an application of the constructor (as returned by
@racket[get-constructor]) to the contents (as returned by
@racket[get-contents]). When given to @racket[write], it is
shown as an unreadable value with the constructor separated
from the contents by a colon.
@(struct-eval '(require racket/struct racket/pretty))
@examples[#:eval struct-eval
(struct point (x y)
#:property prop:custom-write
(make-constructor-style-printer
(lambda (obj) 'point)
(lambda (obj) (list (point-x obj) (point-y obj)))))
(print (point 1 2))
(write (point 1 2))
]
(struct point (x y)
#:methods gen:custom-write
[(define write-proc
(make-constructor-style-printer
(lambda (obj) 'point)
(lambda (obj) (list (point-x obj) (point-y obj)))))])
(print (point 1 2))
(write (point 1 2))]
The function also cooperates with @racket[pretty-print]: