any->boolean: Move from networks to utils.

This commit is contained in:
Sergiu Ivanov 2020-06-03 23:42:47 +02:00
parent e237e9e019
commit 458868ea21
2 changed files with 10 additions and 5 deletions

View File

@ -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)))

View File

@ -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)))