utils: Type pretty-print-set-sets.
This commit is contained in:
parent
2997319f1f
commit
e4f7c956d4
2 changed files with 23 additions and 15 deletions
|
@ -254,6 +254,17 @@ Pretty prints a set by listing its elements in alphabetic order.
|
||||||
(pretty-print-set (set 'a 'b 1))
|
(pretty-print-set (set 'a 'b 1))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(pretty-print-set-sets (ms (Setof (Setof Any)))) String]{
|
||||||
|
|
||||||
|
Pretty-prints a set of sets of symbols.
|
||||||
|
|
||||||
|
Typically used for pretty-printing the annotations on the edges of
|
||||||
|
a state graph.
|
||||||
|
|
||||||
|
@examples[#:eval utils-evaluator
|
||||||
|
(pretty-print-set-sets (set (set 'a 'b) (set 'c)))
|
||||||
|
]}
|
||||||
|
|
||||||
@section{Additional graph utilities}
|
@section{Additional graph utilities}
|
||||||
@defproc[(dotit [graph Graph]) Void]{
|
@defproc[(dotit [graph Graph]) Void]{
|
||||||
|
|
||||||
|
|
27
utils.rkt
27
utils.rkt
|
@ -21,7 +21,7 @@
|
||||||
extract-symbols any->string stringify-variable-mapping string->any
|
extract-symbols any->string stringify-variable-mapping string->any
|
||||||
handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs
|
handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs
|
||||||
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
||||||
list-sets->list-strings pretty-print-set dotit)
|
list-sets->list-strings pretty-print-set pretty-print-set-sets dotit)
|
||||||
|
|
||||||
(define-type Variable Symbol)
|
(define-type Variable Symbol)
|
||||||
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
||||||
|
@ -287,6 +287,15 @@
|
||||||
(test-case "pretty-print-set"
|
(test-case "pretty-print-set"
|
||||||
(check-equal? (pretty-print-set (set 'a 'b 1)) "1 a b")))
|
(check-equal? (pretty-print-set (set 'a 'b 1)) "1 a b")))
|
||||||
|
|
||||||
|
(: pretty-print-set-sets (-> (Setof (Setof Any)) String))
|
||||||
|
(define (pretty-print-set-sets ms)
|
||||||
|
(string-join (for/list ([m ms]) : (Listof String)
|
||||||
|
(format "{~a}" (pretty-print-set m))) ""))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "pretty-print-set-sets"
|
||||||
|
(check-equal? (pretty-print-set-sets (set (set 'a 'b) (set 'c))) "{a b}{c}")))
|
||||||
|
|
||||||
(define dotit (compose display graphviz))
|
(define dotit (compose display graphviz))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -295,14 +304,13 @@
|
||||||
extract-symbols any->string stringify-variable-mapping string->any
|
extract-symbols any->string stringify-variable-mapping string->any
|
||||||
map-sexp read-org-sexp unorg unstringify-pairs
|
map-sexp read-org-sexp unorg unstringify-pairs
|
||||||
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
||||||
list-sets->list-strings pretty-print-set dotit)
|
list-sets->list-strings pretty-print-set pretty-print-set-sets dotit)
|
||||||
|
|
||||||
;;; Untyped section.
|
;;; Untyped section.
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
;; Functions
|
;; Functions
|
||||||
(contract-out [pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)]
|
(contract-out [update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)]
|
||||||
[update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)]
|
|
||||||
[update-graph (->* (graph?)
|
[update-graph (->* (graph?)
|
||||||
(#:v-func (-> any/c any/c)
|
(#:v-func (-> any/c any/c)
|
||||||
#:e-func (-> any/c any/c))
|
#:e-func (-> any/c any/c))
|
||||||
|
@ -344,17 +352,6 @@
|
||||||
(or/c (list/c key-contract val-contract)
|
(or/c (list/c key-contract val-contract)
|
||||||
(cons/c key-contract val-contract)))
|
(cons/c key-contract val-contract)))
|
||||||
|
|
||||||
;;; Pretty-prints a set of sets of symbols.
|
|
||||||
;;;
|
|
||||||
;;; Typically used for pretty-printing the annotations on the edges of
|
|
||||||
;;; the state graph.
|
|
||||||
(define (pretty-print-set-sets ms)
|
|
||||||
(string-join (for/list ([m ms]) (format "{~a}" (pretty-print-set m))) ""))
|
|
||||||
|
|
||||||
(module+ test
|
|
||||||
(test-case "pretty-print-set-sets"
|
|
||||||
(check-equal? (pretty-print-set-sets (set (set 'a 'b) (set 'c))) "{a b}{c}")))
|
|
||||||
|
|
||||||
|
|
||||||
;;; ==========================
|
;;; ==========================
|
||||||
;;; Additional graph utilities
|
;;; Additional graph utilities
|
||||||
|
|
Loading…
Reference in a new issue