From 6d2034f9e5e8f1329ed60effdbf8a27f0382112a Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 18 Sep 2022 01:20:00 +0200 Subject: [PATCH] Add pretty-print-state. And start a new section in the docs. --- networks.rkt | 11 ++++++++++- scribblings/networks.scrbl | 12 ++++++++++++ scribblings/utils.scrbl | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/networks.rkt b/networks.rkt index 48b58fe..5f672bf 100644 --- a/networks.rkt +++ b/networks.rkt @@ -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) diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index c2fccbe..31dc50a 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -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} diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index b753322..5af8c72 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -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]{