From 458868ea217003c29e306b22757c0d0f292dee17 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 3 Jun 2020 23:42:47 +0200 Subject: [PATCH] any->boolean: Move from networks to utils. --- networks.rkt | 4 ---- utils.rkt | 11 ++++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/networks.rkt b/networks.rkt index 9ba6411..bc0dcd2 100644 --- a/networks.rkt +++ b/networks.rkt @@ -51,7 +51,6 @@ [dds-build-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) graph?)] [dds-build-n-step-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) number? graph?)] [pretty-print-state (-> state? string?)] - [any->boolean (-> any/c boolean?)] [pretty-print-boolean-state (-> state? string?)] [pretty-print-state-graph-with (-> graph? (-> state? string?) graph?)] [pretty-print-state-graph (-> graph? graph?)] @@ -573,9 +572,6 @@ (check-equal? (pretty-print-state (make-state '((a . #f) (b . 3) (c . 4)))) "a:#f b:3 c:4"))) -;;; Converts any non-#f value to 1 and #f to 0. -(define (any->boolean x) (if x 1 0)) - ;;; Pretty-prints a state of the network to Boolean values 0 or 1. (define (pretty-print-boolean-state s) (string-join (hash-map s (λ (key val) (format "~a:~a" key (any->boolean val))) #t))) diff --git a/utils.rkt b/utils.rkt index a25ce78..886e26b 100644 --- a/utils.rkt +++ b/utils.rkt @@ -48,7 +48,8 @@ (stream/c exact-nonnegative-integer?)))] [cartesian-product/stream (->* () #:rest (listof stream?) stream?)] [boolean-power (-> number? (listof (listof boolean?)))] - [boolean-power/stream (-> number? (stream/c (listof boolean?)))]) + [boolean-power/stream (-> number? (stream/c (listof boolean?)))] + [any->boolean (-> any/c boolean?)]) ;; Contracts (contract-out [variable-mapping? contract?] [string-variable-mapping? contract?] @@ -696,3 +697,11 @@ (module+ test (test-case "boolean-power/stream" (check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t))))) + +;;; Converts any non-#f value to 1 and #f to 0. +(define (any->boolean x) (if x 1 0)) + +(module+ test + (test-case "any->boolean" + (check-equal? (any->boolean #t) 1) + (check-equal? (any->boolean #f) 0)))