utils: variable-mapping-stringify -> stringify-variable-mapping.

This commit is contained in:
Sergiu Ivanov 2020-02-22 12:12:57 +01:00
parent 1eb48bc5e2
commit 7d52533f74
2 changed files with 4 additions and 4 deletions

View file

@ -38,7 +38,7 @@
(check-equal? (any->string 'a) "a")
(check-equal? (any->string '(a 1 (x y))) "(a 1 (x y))")
(check-equal? (any->string "hello") "hello")
(let ([mp (variable-mapping-stringify #hash((a . (and a b)) (b . (not b))))])
(let ([mp (stringify-variable-mapping #hash((a . (and a b)) (b . (not b))))])
(check-equal? (hash-ref mp 'a) "(and a b)")
(check-equal? (hash-ref mp 'b) "(not b)"))
(let ([mp (sgfy #hash((a . (and a b)) (b . (not b))))])

View file

@ -12,7 +12,7 @@
(contract-out [eval-with (-> variable-mapping? any/c any)]
[extract-symbols (-> any/c list?)]
[any->string (-> any/c string?)]
[variable-mapping-stringify (-> variable-mapping? string-variable-mapping?)]
[stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)]
[string->any (-> string? any/c)])
;; Contracts
(contract-out [variable-mapping? contract?]
@ -157,12 +157,12 @@
(define (string-variable-mapping? dict) (hash/c symbol? string?))
;;; Converts all the values of a variable mapping to string.
(define (variable-mapping-stringify ht)
(define (stringify-variable-mapping ht)
(make-hash (hash-map ht (λ (key val)
(cons key (any->string val))))))
;;; A shortcut for variable-mapping-stingify.
(define-syntax-rule (sgfy ht) (variable-mapping-stringify ht))
(define-syntax-rule (sgfy ht) (stringify-variable-mapping ht))
;;; Reads any value from string.
(define (string->any str)