From 180810a2aa278ee13c043d85fd45f1ea5264e06b Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sat, 6 Jun 2020 08:23:55 +0200 Subject: [PATCH] utils: 0-1 -> 01 Shorter and easier to type. --- networks.rkt | 2 +- utils.rkt | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/networks.rkt b/networks.rkt index fcad756..c786282 100644 --- a/networks.rkt +++ b/networks.rkt @@ -574,7 +574,7 @@ ;;; 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->0-1 val))) #t))) + (string-join (hash-map s (λ (key val) (format "~a:~a" key (any->01 val))) #t))) (module+ test (test-case "pretty-print-boolean-state" diff --git a/utils.rkt b/utils.rkt index 1ac2e9e..bf49462 100644 --- a/utils.rkt +++ b/utils.rkt @@ -49,8 +49,8 @@ [cartesian-product/stream (->* () #:rest (listof stream?) stream?)] [boolean-power (-> number? (listof (listof boolean?)))] [boolean-power/stream (-> number? (stream/c (listof boolean?)))] - [any->0-1 (-> any/c (or/c 0 1))] - [0-1->boolean (-> (or/c 0 1) boolean?)]) + [any->01 (-> any/c (or/c 0 1))] + [01->boolean (-> (or/c 0 1) boolean?)]) ;; Contracts (contract-out [variable-mapping? contract?] [string-variable-mapping? contract?] @@ -700,18 +700,18 @@ (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->0-1 x) (if x 1 0)) +(define (any->01 x) (if x 1 0)) (module+ test - (test-case "any->0-1" - (check-equal? (any->0-1 #t) 1) - (check-equal? (any->0-1 #f) 0))) + (test-case "any->01" + (check-equal? (any->01 #t) 1) + (check-equal? (any->01 #f) 0))) ;;; Converts 0 to #f and 1 to #t -(define (0-1->boolean x) +(define (01->boolean x) (case x [(0) #f] [else #t])) (module+ test - (test-case "0-1->boolean" - (check-equal? (0-1->boolean 0) #f) - (check-equal? (0-1->boolean 1) #t))) + (test-case "01->boolean" + (check-equal? (01->boolean 0) #f) + (check-equal? (01->boolean 1) #t)))