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:
parent
5cc030e2ad
commit
f549724e36
|
@ -1,5 +1,5 @@
|
||||||
#lang scribble/doc
|
#lang scribble/doc
|
||||||
@(require "mz.rkt")
|
@(require "mz.rkt" (for-label racket/struct-info))
|
||||||
|
|
||||||
@title{Printer Extension}
|
@title{Printer Extension}
|
||||||
|
|
||||||
|
@ -77,6 +77,22 @@ so that graph and cycle structure can be represented.
|
||||||
(vector-set! (tuple-ref t) 0 t)
|
(vector-set! (tuple-ref t) 0 t)
|
||||||
(write 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?]{
|
@defthing[prop:custom-write struct-type-property?]{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#lang scribble/doc
|
#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-eval (make-base-eval))
|
||||||
@(define struct-copy-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?)])
|
[get-contents (-> any/c sequence?)])
|
||||||
(-> any/c output-port? (or/c #t #f 0 1) void?)]{
|
(-> any/c output-port? (or/c #t #f 0 1) void?)]{
|
||||||
|
|
||||||
Produces a function suitable as a value for @racket[prop:custom-write]. The
|
Produces a function suitable as a value for
|
||||||
function prints values in ``constructor style.'' When the value is
|
@racket[gen:custom-write] or @racket[prop:custom-write].
|
||||||
@racket[print]ed as an expression, it is shown as an application of the
|
The function prints values in ``constructor style.'' When
|
||||||
constructor (as returned by @racket[get-constructor]) to the contents (as
|
the value is @racket[print]ed as an expression, it is shown
|
||||||
returned by @racket[get-contents]). When given to @racket[write], it is shown as
|
as an application of the constructor (as returned by
|
||||||
an unreadable value with the constructor separated from the contents by a colon.
|
@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))
|
@(struct-eval '(require racket/struct racket/pretty))
|
||||||
|
|
||||||
@examples[#:eval struct-eval
|
@examples[#:eval struct-eval
|
||||||
(struct point (x y)
|
(struct point (x y)
|
||||||
#:property prop:custom-write
|
#:methods gen:custom-write
|
||||||
|
[(define write-proc
|
||||||
(make-constructor-style-printer
|
(make-constructor-style-printer
|
||||||
(lambda (obj) 'point)
|
(lambda (obj) 'point)
|
||||||
(lambda (obj) (list (point-x obj) (point-y obj)))))
|
(lambda (obj) (list (point-x obj) (point-y obj)))))])
|
||||||
(print (point 1 2))
|
(print (point 1 2))
|
||||||
(write (point 1 2))
|
(write (point 1 2))]
|
||||||
]
|
|
||||||
|
|
||||||
The function also cooperates with @racket[pretty-print]:
|
The function also cooperates with @racket[pretty-print]:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user