From 3f24a5be8b85e2d2ea354c437affd6e9e00002e4 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 1 Mar 2020 15:15:52 +0100 Subject: [PATCH] utils: Add pretty-print-set. --- utils-tests.rkt | 3 +++ utils.rkt | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/utils-tests.rkt b/utils-tests.rkt index 593ada8..62140e1 100644 --- a/utils-tests.rkt +++ b/utils-tests.rkt @@ -107,3 +107,6 @@ (check-false (has-edge? new-gr3 'cc 'bb)) (check-equal? (edge-weight new-gr3 'aa 'bb) 20) (check-equal? (edge-weight new-gr3 'bb 'cc) 22))) + +(test-case "Pretty printing" + (check-equal? (pretty-print-set (set 'a 'b 1)) "1 a b")) diff --git a/utils.rkt b/utils.rkt index 90ea98b..86782e6 100644 --- a/utils.rkt +++ b/utils.rkt @@ -23,7 +23,8 @@ [update-graph (->* (graph?) (#:v-func (-> any/c any/c) #:e-func (-> any/c any/c)) - graph?)]) + graph?)] + [pretty-print-set (-> generic-set? string?)]) ;; Contracts (contract-out [variable-mapping? contract?] [string-variable-mapping? contract?] @@ -249,3 +250,12 @@ (if (unweighted-graph? gr) (unweighted-graph/directed edges) (weighted-graph/directed edges)))) + + +;;; =============== +;;; Pretty printing +;;; =============== + +;;; Pretty print a set by listing its elements in alphabetic order. +(define (pretty-print-set s) + (string-join (sort (set-map s any->string) string