utils.rkt: Copy stringify-variable-mapping.

This commit is contained in:
Sergiu Ivanov 2020-12-05 00:22:49 +01:00
parent c063723b5c
commit 87ab73d0c3
3 changed files with 22 additions and 4 deletions

View file

@ -2,7 +2,7 @@
@(require scribble/example racket/sandbox
(for-label racket graph "../utils.rkt"
(only-in typed/racket/base
Any AnyValues Listof)))
Any AnyValues Listof String)))
@title[#:tag "utils"]{dds/utils: Various Utilities}
@ -139,6 +139,14 @@ the result in a string.
(any->string '(a 1 (x y)))
]}
@defproc[(stringify-variable-mapping [ht (VariableMapping Any)]) (VariableMapping String)]{
Converts all the values of a @racket[VariableMapping] to string.
@examples[#:eval utils-evaluator
(stringify-variable-mapping (hash 'a '(and a b) 'b '(not b)))
]}
@section{Additional graph utilities}
@section{Pretty printing}

View file

@ -10,8 +10,7 @@
(provide
;; Functions
(contract-out [stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)]
[string->any (-> string? any/c)]
(contract-out [string->any (-> string? any/c)]
[read-org-sexp (-> string? (listof any/c))]
[map-sexp (-> procedure? any/c any/c)]
[unorg (-> string? (listof any/c))]

View file

@ -5,7 +5,7 @@
(provide Symbol VariableMapping
eval-with eval1-with
extract-symbols
any->string
any->string stringify-variable-mapping
;; Syntax
auto-hash-ref/explicit auto-hash-ref/:)
@ -140,3 +140,14 @@
(check-equal? (any->string 'a) "a")
(check-equal? (any->string '(a 1 (x y))) "(a 1 (x y))")
(check-equal? (any->string "hello") "hello")))
(: stringify-variable-mapping (-> (VariableMapping Any) (VariableMapping String)))
(define (stringify-variable-mapping ht)
(for/hash : (VariableMapping String)
([(key val) (in-hash ht)]) (values key (any->string val))))
(module+ test
(test-case "stringify-variable-mapping"
(define 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)")))