From 2dd9e9e5753ccd7d79a81b4d31866a85d51cd271 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sat, 22 Feb 2020 10:35:01 +0100 Subject: [PATCH] utils: Use hash/c instead of hash-pred. Also remove hash-pred. --- utils.rkt | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/utils.rkt b/utils.rkt index d0435d0..9666e9b 100644 --- a/utils.rkt +++ b/utils.rkt @@ -11,13 +11,10 @@ ;; Functions (contract-out [eval-with (-> variable-mapping? any/c any)] [extract-symbols (-> any/c list?)] - [variable-mapping? (-> any/c boolean?)] - [hash-pred (->* (hash?) - (#:key-pred any/c #:val-pred any/c) - boolean?)] + [variable-mapping? contract?] [any->string (-> any/c string?)] [variable-mapping-stringify (-> variable-mapping? string-variable-mapping?)] - [string-variable-mapping? (-> any/c boolean?)]) + [string-variable-mapping? contract?]) ;; Syntax auto-hash-ref/explicit auto-hash-ref/:) @@ -29,19 +26,8 @@ ;;; usage of hash tables mapping symbols to values. The goal is ;;; essentially to avoid having to write explicit hash-ref calls. -;;; Checks whether dict is a hash table and whether its keys satisfy -;;; key-pred and its values satisfy val-pred. If either of the -;;; predicates is not supplied, it defaults to true. For example, -;;; (hash-pred dict) is equivalent to (hash dict). -(define/match (hash-pred dict - #:key-pred [key-pred (λ (_) #t)] - #:val-pred [val-pred (λ (_) #t)]) - [((hash-table (keys vals) ...) key-pred val-pred) - (and (andmap key-pred keys) (andmap val-pred vals))] - [(_ _ _) #f]) - ;;; A variable mapping is a hash table mapping symbols to values. -(define (variable-mapping? dict) (hash-pred dict #:key-pred symbol?)) +(define (variable-mapping? dict) (hash/c symbol? any/c)) ;;; Given a (HashTable Symbol a) and a sequence of symbols, binds ;;; these symbols to the values they are associated to in the hash @@ -166,7 +152,7 @@ (with-output-to-string (λ () (display x)))) ;;; A string variable mapping is a mapping from variables to strings. -(define (string-variable-mapping? dict) (hash-pred dict #:key-pred symbol? #:val-pred string?)) +(define (string-variable-mapping? dict) (hash/c symbol? string?)) ;;; Converts all the values of a variable mapping to string. (define (variable-mapping-stringify ht)