diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 0d71789..44dba17 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -246,6 +246,13 @@ those symbols. @section{Pretty printing} +@defproc[(pretty-print-set (s (Setof Any))) String]{ + +Pretty print a set by listing its elements in alphabetic order. + +@examples[#:eval utils-evaluator +(pretty-print-set (set 'a 'b 1)) +]} @section{Additional list and hash map utilities} @section{Functions and procedures} diff --git a/utils-untyped.rkt b/utils-untyped.rkt index bd19da0..4c1a8b6 100644 --- a/utils-untyped.rkt +++ b/utils-untyped.rkt @@ -16,7 +16,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))))] diff --git a/utils.rkt b/utils.rkt index 8217d48..01705cf 100644 --- a/utils.rkt +++ b/utils.rkt @@ -10,7 +10,7 @@ any->string 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 + list-sets->list-strings pretty-print-set ;; Syntax auto-hash-ref/explicit auto-hash-ref/:) @@ -283,3 +283,11 @@ (test-case "list-sets->list-strings" (check-equal? (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't))) '("y x" "z" "" "t")))) + +(: pretty-print-set (-> (Setof Any) String)) +(define (pretty-print-set s) + (string-join (sort (set-map s any->string) string