utils: Use hash/c instead of hash-pred.

Also remove hash-pred.
This commit is contained in:
Sergiu Ivanov 2020-02-22 10:35:01 +01:00
parent 184727f5b4
commit 2dd9e9e575
1 changed files with 4 additions and 18 deletions

View File

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