Docs for gen:custom-write.
This commit is contained in:
parent
13b82e9a59
commit
cee88f05dd
|
@ -3,15 +3,14 @@
|
||||||
|
|
||||||
@title{Printer Extension}
|
@title{Printer Extension}
|
||||||
|
|
||||||
@defthing[prop:custom-write struct-type-property?]{
|
@defthing[gen:custom-write any/c]{
|
||||||
|
|
||||||
Associates a procedure to a structure type used by the default
|
A @tech{generic interface} (see @secref["struct-generics"]) that
|
||||||
printer to @racket[display], @racket[write], or @racket[print]
|
supplies a method, @racket[write-proc] used by the default printer to
|
||||||
instances of the structure type.
|
@racket[display], @racket[write], or @racket[print] instances of the
|
||||||
|
structure type.
|
||||||
|
|
||||||
@moreref["structprops"]{structure type properties}
|
A @racket[write-proc] method takes three
|
||||||
|
|
||||||
The procedure for a @racket[prop:custom-write] value takes three
|
|
||||||
arguments: the structure to be printed, the target port, and an
|
arguments: the structure to be printed, the target port, and an
|
||||||
argument that is @racket[#t] for @racket[write] mode, @racket[#f] for
|
argument that is @racket[#t] for @racket[write] mode, @racket[#f] for
|
||||||
@racket[display] mode, or @racket[0] or @racket[1] indicating
|
@racket[display] mode, or @racket[0] or @racket[1] indicating
|
||||||
|
@ -51,7 +50,7 @@ so that graph and cycle structure can be represented.
|
||||||
@defexamples[
|
@defexamples[
|
||||||
(define (tuple-print tuple port mode)
|
(define (tuple-print tuple port mode)
|
||||||
(when mode (write-string "<" port))
|
(when mode (write-string "<" port))
|
||||||
(let ([l (tuple-ref tuple 0)]
|
(let ([l (tuple-ref tuple)]
|
||||||
[recur (case mode
|
[recur (case mode
|
||||||
[(#t) write]
|
[(#t) write]
|
||||||
[(#f) display]
|
[(#f) display]
|
||||||
|
@ -64,20 +63,26 @@ so that graph and cycle structure can be represented.
|
||||||
(cdr (vector->list l)))))
|
(cdr (vector->list l)))))
|
||||||
(when mode (write-string ">" port)))
|
(when mode (write-string ">" port)))
|
||||||
|
|
||||||
(define-values (s:tuple make-tuple tuple? tuple-ref tuple-set!)
|
(struct tuple (ref)
|
||||||
(make-struct-type 'tuple #f 1 0 #f
|
#:methods gen:custom-write
|
||||||
(list (cons prop:custom-write tuple-print))))
|
[(define write-proc tuple-print)])
|
||||||
|
|
||||||
(display (make-tuple #(1 2 "a")))
|
(display (tuple #(1 2 "a")))
|
||||||
|
|
||||||
(print (make-tuple #(1 2 "a")))
|
(print (tuple #(1 2 "a")))
|
||||||
|
|
||||||
(let ([t (make-tuple (vector 1 2 "a"))])
|
(let ([t (tuple (vector 1 2 "a"))])
|
||||||
(vector-set! (tuple-ref t 0) 0 t)
|
(vector-set! (tuple-ref t) 0 t)
|
||||||
(write t))
|
(write t))
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@defthing[prop:custom-write struct-type-property?]{
|
||||||
|
A deprecated @tech{structure type property} (see @secref["structprops"])
|
||||||
|
that supplies a procedure that corresponds to @racket[gen:custom-write]'s
|
||||||
|
@racket[write-proc]. @racket[gen:custom-write] should be used instead.
|
||||||
|
}
|
||||||
|
|
||||||
@defproc[(custom-write? [v any/c]) boolean?]{
|
@defproc[(custom-write? [v any/c]) boolean?]{
|
||||||
|
|
||||||
Returns @racket[#t] if @racket[v] has the @racket[prop:custom-write]
|
Returns @racket[#t] if @racket[v] has the @racket[prop:custom-write]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user