From 22f5e149c6ae15a3a839126edc8c069b5c53e075 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 18 Jan 2019 17:42:17 -0800 Subject: [PATCH] the play --- quad/quad/atomize.rkt | 14 ++++---------- quad/quad/quad.rkt | 9 +++------ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/quad/quad/atomize.rkt b/quad/quad/atomize.rkt index 27d1b02a..f9c03e1b 100644 --- a/quad/quad/atomize.rkt +++ b/quad/quad/atomize.rkt @@ -3,6 +3,7 @@ racket/hash racket/match racket/list + racket/struct txexpr racket/function "quad.rkt" @@ -65,16 +66,9 @@ (for/list ([elem (in-list (merge-adjacent-strings elems 'isolate-white))]) (match elem [(? string?) - ;; 190116 caveat: all quads with strings as elements will be atomized. - ;; however, if the starting quad has a struct subtype of quad, - ;; this subtype will be lost. - ;; IOW, all atomized quads are of the base `quad` type. - ;; this is because we can't get access to any subtype constructors here. - ;; corollary: quads that need to keep their types should not have any strings as elements. - ;; also, they will not have any run keys embedded - ;; (but they shouldn't need it because they're not part of text runs) - ;; overall I am persuaded that `atomize` is very texty and needs a name befitting that role. - (list ((quad-copier x) x next-attrs (list elem)))] + (define-values (xtype _) (struct-info x)) + (define x-constructor (struct-type-make-constructor xtype)) + (list (apply x-constructor (list* next-attrs (list elem) (cddr (struct->list x)))))] [_ (loop elem next-attrs next-key)])))] [_ (list x)]))) diff --git a/quad/quad/quad.rkt b/quad/quad/quad.rkt index 8b55bfdf..213a9f4b 100644 --- a/quad/quad/quad.rkt +++ b/quad/quad/quad.rkt @@ -34,9 +34,7 @@ ;; and compare them key-by-key (hashes-equal? (quad-attrs q1) (quad-attrs q2)))) -(struct quad (type - copier - attrs +(struct quad (attrs elems size in @@ -48,6 +46,7 @@ draw-start draw draw-end) + #:transparent #:property prop:custom-write (λ (v p w?) (display (format "" @@ -97,9 +96,7 @@ [(list (? dict? assocs) elems ...) assocs (make-quad #:attrs (make-hasheq assocs) #:elems elems)] [(list elems ..1) (make-quad #:elems elems)] ;; all cases end up below - [null (type type - copier - attrs + [null (type attrs elems size in