From 5519a8ab458521177a4e3398125280718adb86b7 Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Fri, 4 Aug 2017 11:09:45 -0400 Subject: [PATCH] example of unquoted-printing-string in make-constructor-style-printer --- .../scribblings/reference/struct.scrbl | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pkgs/racket-doc/scribblings/reference/struct.scrbl b/pkgs/racket-doc/scribblings/reference/struct.scrbl index 971684ac07..5a3e1c8a83 100644 --- a/pkgs/racket-doc/scribblings/reference/struct.scrbl +++ b/pkgs/racket-doc/scribblings/reference/struct.scrbl @@ -640,13 +640,35 @@ See @racket[make-prefab-struct] for a description of valid key shapes.} The function also cooperates with @racket[pretty-print]: -@examples[#:eval struct-eval +@examples[#:eval struct-eval #:label #f (parameterize ((pretty-print-columns 10)) (pretty-print (point #e3e6 #e4e6))) (parameterize ((pretty-print-columns 10)) (pretty-write (point #e3e6 #e4e6))) ] +Keyword arguments can be simulated with @racket[unquoted-printing-string]: + +@examples[#:eval struct-eval #:label #f +(code:comment "Private implementation") +(struct kwpoint-impl (x y) + #:methods gen:custom-write + [(define write-proc + (make-constructor-style-printer + (lambda (obj) 'kwpoint) + (lambda (obj) + (list (unquoted-printing-string "#:x") + (kwpoint-impl-x obj) + (unquoted-printing-string "#:y") + (kwpoint-impl-y obj)))))]) +(code:comment "Public ``constructor''") +(define (kwpoint #:x x #:y y) + (kwpoint-impl x y)) +(code:comment "Example use") +(print (kwpoint #:x 1 #:y 2)) +(write (kwpoint #:x 3 #:y 4)) +] + @history[#:added "6.3"]{} }