From 6e0f85ba31807acb574168c39e06c06dd3a0775a Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 4 Apr 2019 09:58:23 -0700 Subject: [PATCH] shorten quad printing & add parameter --- quad/quad/quad.rkt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/quad/quad/quad.rkt b/quad/quad/quad.rkt index f07d41e6..bf4bc4a7 100644 --- a/quad/quad/quad.rkt +++ b/quad/quad/quad.rkt @@ -35,6 +35,8 @@ ;; and compare them key-by-key (hashes-equal? (quad-attrs q1) (quad-attrs q2)))) +(define verbose-quad-printing? (make-parameter #f)) + (struct quad (attrs ; key-value pairs, arbitrary elems ; subquads or text ;; size is a two-dim pt @@ -53,11 +55,14 @@ ) #:transparent #:property prop:custom-write - (λ (v p w?) (display - (format "" - (string-join (map ~v (flatten (hash->list (quad-attrs v)))) + (λ (q p w?) (display + (format "<~a~a~a>" + (object-name q) + (if (verbose-quad-printing?) + (string-join (map ~v (flatten (hash->list (quad-attrs q)))) " " #:before-first "(" #:after-last ")") - (string-join (map ~v (quad-elems v)) " " #:before-first " ")) p)) + "") + (string-join (map ~v (quad-elems q)) " " #:before-first " ")) p)) #:methods gen:equal+hash [(define equal-proc quad=?) (define (hash-proc h recur) (equal-hash-code h))