From 2997319f1f8b81ad351241a84de7cd2bd8e78794 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Thu, 3 Feb 2022 23:56:28 +0100 Subject: [PATCH] utils: Type pretty-print-set. --- scribblings/utils.scrbl | 8 ++++++++ utils.rkt | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 43da82f..bc8e1cb 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -246,6 +246,14 @@ those symbols. (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't))) ]} +@defproc[(pretty-print-set (s (Setof Any))) String]{ + +Pretty prints a set by listing its elements in alphabetic order. + +@examples[#:eval utils-evaluator +(pretty-print-set (set 'a 'b 1)) +]} + @section{Additional graph utilities} @defproc[(dotit [graph Graph]) Void]{ diff --git a/utils.rkt b/utils.rkt index f074d75..2a7b7ef 100644 --- a/utils.rkt +++ b/utils.rkt @@ -21,7 +21,7 @@ extract-symbols any->string stringify-variable-mapping string->any handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs read-org-variable-mapping unorgv read-symbol-list drop-first-last - list-sets->list-strings dotit) + list-sets->list-strings pretty-print-set dotit) (define-type Variable Symbol) (define-type (VariableMapping A) (Immutable-HashTable Variable A)) @@ -279,6 +279,14 @@ (check-equal? (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't))) '("x y" "z" "" "t")))) + (: pretty-print-set (-> (Setof Any) String)) + (define (pretty-print-set s) + (string-join (sort (set-map s any->string) stringstring stringify-variable-mapping string->any map-sexp read-org-sexp unorg unstringify-pairs read-org-variable-mapping unorgv read-symbol-list drop-first-last - list-sets->list-strings dotit) + list-sets->list-strings pretty-print-set dotit) ;;; Untyped section. @@ -299,7 +307,6 @@ (#:v-func (-> any/c any/c) #:e-func (-> any/c any/c)) graph?)] - [pretty-print-set (-> generic-set? string?)] [collect-by-key (-> (listof any/c) (listof any/c) (values (listof any/c) (listof (listof any/c))))] [collect-by-key/sets (-> (listof any/c) (listof any/c) (values (listof any/c) (listof (set/c any/c))))]