From f549724e36c141989f4d1d2d103f5b65e740865e Mon Sep 17 00:00:00 2001 From: Leif Andersen Date: Mon, 25 Apr 2016 19:18:11 -0400 Subject: [PATCH] Updated scribble docs for make-constructor-style-printer It should be using gen:custom-write rather than prop:custom-write. --- .../scribblings/reference/custom-write.scrbl | 18 +++++++++- .../scribblings/reference/struct.scrbl | 33 ++++++++++--------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/pkgs/racket-doc/scribblings/reference/custom-write.scrbl b/pkgs/racket-doc/scribblings/reference/custom-write.scrbl index ed0d66af3d..8047593302 100644 --- a/pkgs/racket-doc/scribblings/reference/custom-write.scrbl +++ b/pkgs/racket-doc/scribblings/reference/custom-write.scrbl @@ -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?]{ diff --git a/pkgs/racket-doc/scribblings/reference/struct.scrbl b/pkgs/racket-doc/scribblings/reference/struct.scrbl index 1d0aa270ba..b9b379565b 100644 --- a/pkgs/racket-doc/scribblings/reference/struct.scrbl +++ b/pkgs/racket-doc/scribblings/reference/struct.scrbl @@ -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]: