From 3a873ab256a40bc43ec230c89de790b6996996c1 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 23 Feb 2020 19:24:53 +0100 Subject: [PATCH] networks: Add pretty-print-state. --- networks-tests.rkt | 1 + networks.rkt | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/networks-tests.rkt b/networks-tests.rkt index a7f8420..0406aee 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -98,6 +98,7 @@ (check-equal? (edge-weight sig2 'b 'a) -1))) (test-case "Dynamics of networks" + (check-equal? (pretty-print-state (st '((a . #f) (b . 3)))) "a:#f b:3") (let ([vars '(a b c)]) (check-equal? (make-asyn vars) (set (set 'a) (set 'b) (set 'c))) (check-equal? (make-syn vars) (set (set 'a 'b 'c)))) diff --git a/networks.rkt b/networks.rkt index 19a329b..bbd9d8d 100644 --- a/networks.rkt +++ b/networks.rkt @@ -40,7 +40,8 @@ [dds-step-one-annotated (-> dynamics? state? (set/c (cons/c modality? state?)))] [dds-step (-> dynamics? (set/c state? #:kind 'dont-care) (set/c state?))] [dds-build-state-graph (-> dynamics? (set/c state? #:kind 'dont-care) graph?)] - [dds-build-n-step-state-graph (-> dynamics? (set/c state? #:kind 'dont-care) number? graph?)]) + [dds-build-n-step-state-graph (-> dynamics? (set/c state? #:kind 'dont-care) number? graph?)] + [pretty-print-state (-> state? string?)]) ;; Predicates (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)] @@ -299,3 +300,7 @@ ;;; Creates the synchronous dynamics for a given network. (define (make-syn-dynamics network) (make-dynamics-from-func network make-syn)) + +;;; Pretty-prints a state of the network. +(define (pretty-print-state s) + (string-join (for/list ([(key val) s]) (format "~a:~a" key val))))