utils: Use hash/c instead of hash-pred.
Also remove hash-pred.
This commit is contained in:
parent
184727f5b4
commit
2dd9e9e575
1 changed files with 4 additions and 18 deletions
22
utils.rkt
22
utils.rkt
|
@ -11,13 +11,10 @@
|
||||||
;; Functions
|
;; Functions
|
||||||
(contract-out [eval-with (-> variable-mapping? any/c any)]
|
(contract-out [eval-with (-> variable-mapping? any/c any)]
|
||||||
[extract-symbols (-> any/c list?)]
|
[extract-symbols (-> any/c list?)]
|
||||||
[variable-mapping? (-> any/c boolean?)]
|
[variable-mapping? contract?]
|
||||||
[hash-pred (->* (hash?)
|
|
||||||
(#:key-pred any/c #:val-pred any/c)
|
|
||||||
boolean?)]
|
|
||||||
[any->string (-> any/c string?)]
|
[any->string (-> any/c string?)]
|
||||||
[variable-mapping-stringify (-> variable-mapping? string-variable-mapping?)]
|
[variable-mapping-stringify (-> variable-mapping? string-variable-mapping?)]
|
||||||
[string-variable-mapping? (-> any/c boolean?)])
|
[string-variable-mapping? contract?])
|
||||||
;; Syntax
|
;; Syntax
|
||||||
auto-hash-ref/explicit auto-hash-ref/:)
|
auto-hash-ref/explicit auto-hash-ref/:)
|
||||||
|
|
||||||
|
@ -29,19 +26,8 @@
|
||||||
;;; usage of hash tables mapping symbols to values. The goal is
|
;;; usage of hash tables mapping symbols to values. The goal is
|
||||||
;;; essentially to avoid having to write explicit hash-ref calls.
|
;;; 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.
|
;;; 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
|
;;; Given a (HashTable Symbol a) and a sequence of symbols, binds
|
||||||
;;; these symbols to the values they are associated to in the hash
|
;;; these symbols to the values they are associated to in the hash
|
||||||
|
@ -166,7 +152,7 @@
|
||||||
(with-output-to-string (λ () (display x))))
|
(with-output-to-string (λ () (display x))))
|
||||||
|
|
||||||
;;; A string variable mapping is a mapping from variables to strings.
|
;;; 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.
|
;;; Converts all the values of a variable mapping to string.
|
||||||
(define (variable-mapping-stringify ht)
|
(define (variable-mapping-stringify ht)
|
||||||
|
|
Loading…
Reference in a new issue