From 6c9071fd88443d65043460bff38f32d5e0a33a88 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 25 May 2021 11:05:16 +0200 Subject: [PATCH] Optionally omit commas when writing preserves --- .../racket/preserves/preserves/write-text.rkt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/implementations/racket/preserves/preserves/write-text.rkt b/implementations/racket/preserves/preserves/write-text.rkt index cbafc10..4ed996f 100644 --- a/implementations/racket/preserves/preserves/write-text.rkt +++ b/implementations/racket/preserves/preserves/write-text.rkt @@ -26,6 +26,7 @@ (define (write-preserve/text v0 [o (current-output-port)] #:indent [indent-amount0 #f] #:encode-embedded [encode-embedded0 #f] + #:commas? [commas? #t] #:write-annotations? [write-annotations? #t]) (define encode-embedded (or encode-embedded0 object-id)) (define indent-amount (match indent-amount0 @@ -164,9 +165,9 @@ [_ (write-stringlike-char c)])) (! "|")))] [(record label fields) (write-record distance label fields)] - [(? list?) (write-sequence distance "[" "," "]" write-value v)] - [(? set?) (write-sequence distance "#{" "," "}" write-value (set->list v))] - [(? dict?) (write-sequence distance "{" "," "}" write-key-value (dict->list v))] + [(? list?) (write-sequence distance "[" (if commas? "," "") "]" write-value v)] + [(? set?) (write-sequence distance "#{" (if commas? "," "") "}" write-value (set->list v))] + [(? dict?) (write-sequence distance "{" (if commas? "," "") "}" write-key-value (dict->list v))] [other (! "#!") (write-value distance (encode-embedded other))])) @@ -176,9 +177,11 @@ (define (preserve->string v0 #:indent [indent-amount #f] #:encode-embedded [encode-embedded #f] + #:commas? [commas? #t] #:write-annotations? [write-annotations? #t]) (with-output-to-string (lambda () (write-preserve/text v0 #:indent indent-amount #:encode-embedded encode-embedded + #:commas? commas? #:write-annotations? write-annotations?))))