Add pretty-print-state.

And start a new section in the docs.
This commit is contained in:
Sergiu Ivanov 2022-09-18 01:20:00 +02:00
parent 945626487c
commit 6d2034f9e5
3 changed files with 23 additions and 2 deletions

View File

@ -34,7 +34,7 @@
build-signed-interaction-graph/form
Modality Mode dynamics% Dynamics% make-syn make-asyn
make-asyn-dynamics make-syn-dynamics
make-asyn-dynamics make-syn-dynamics pretty-print-state
)
(define-type (State a) (VariableMapping a))
@ -655,6 +655,15 @@
(define m (get-field mode syn-dyn))
(check-equal? (length m) 1)
(check-true (set=? (car m) '(x y z)))))
(: pretty-print-state (All (a) (-> (State a) String)))
(define (pretty-print-state s)
(string-join (hash-map s (λ (key val) (format "~a:~a" key val)) #t)))
(module+ test
(test-case "pretty-print-state"
(check-equal? (pretty-print-state (hash 'a #f 'b 3 'c 4))
"a:#f b:3 c:4")))
)
(require 'typed)

View File

@ -463,6 +463,18 @@ Creates the synchronous dynamics for a given network: an instance of
}
@section[#:tag "networks_Pretty_printing"]{Pretty printing}
This section defines various functions for nicely formatting node and edge
labels in state graphs of networks.
@defproc[(pretty-print-state [s (State a)]) String]{
Pretty-prints a state of a network.
@ex[(pretty-print-state (hash 'a #f 'b 3 'c 4))]
}
@section{Inferring interaction graphs}

View File

@ -310,7 +310,7 @@ those symbols.
(list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't)))
]}
@section{Pretty printing}
@section[#:tag "utils_Pretty_printing"]{Pretty printing}
@defproc[(pretty-print-set (s (Setof Any))) String]{