utils.rkt: Copy stringify-variable-mapping.
This commit is contained in:
parent
c9d36ea45e
commit
1273a9595f
3 changed files with 22 additions and 4 deletions
|
@ -2,7 +2,7 @@
|
||||||
@(require scribble/example racket/sandbox
|
@(require scribble/example racket/sandbox
|
||||||
(for-label racket graph "../utils.rkt"
|
(for-label racket graph "../utils.rkt"
|
||||||
(only-in typed/racket/base
|
(only-in typed/racket/base
|
||||||
Any AnyValues Listof)))
|
Any AnyValues Listof String)))
|
||||||
|
|
||||||
@title[#:tag "utils"]{dds/utils: Various Utilities}
|
@title[#:tag "utils"]{dds/utils: Various Utilities}
|
||||||
|
|
||||||
|
@ -139,6 +139,14 @@ the result in a string.
|
||||||
(any->string '(a 1 (x y)))
|
(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{Additional graph utilities}
|
||||||
|
|
||||||
@section{Pretty printing}
|
@section{Pretty printing}
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
;; Functions
|
;; Functions
|
||||||
(contract-out [stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)]
|
(contract-out [string->any (-> string? any/c)]
|
||||||
[string->any (-> string? any/c)]
|
|
||||||
[read-org-sexp (-> string? (listof any/c))]
|
[read-org-sexp (-> string? (listof any/c))]
|
||||||
[map-sexp (-> procedure? any/c any/c)]
|
[map-sexp (-> procedure? any/c any/c)]
|
||||||
[unorg (-> string? (listof any/c))]
|
[unorg (-> string? (listof any/c))]
|
||||||
|
|
13
utils.rkt
13
utils.rkt
|
@ -5,7 +5,7 @@
|
||||||
(provide Symbol VariableMapping
|
(provide Symbol VariableMapping
|
||||||
eval-with eval1-with
|
eval-with eval1-with
|
||||||
extract-symbols
|
extract-symbols
|
||||||
any->string
|
any->string stringify-variable-mapping
|
||||||
;; Syntax
|
;; Syntax
|
||||||
auto-hash-ref/explicit auto-hash-ref/:)
|
auto-hash-ref/explicit auto-hash-ref/:)
|
||||||
|
|
||||||
|
@ -140,3 +140,14 @@
|
||||||
(check-equal? (any->string 'a) "a")
|
(check-equal? (any->string 'a) "a")
|
||||||
(check-equal? (any->string '(a 1 (x y))) "(a 1 (x y))")
|
(check-equal? (any->string '(a 1 (x y))) "(a 1 (x y))")
|
||||||
(check-equal? (any->string "hello") "hello")))
|
(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)")))
|
||||||
|
|
Loading…
Reference in a new issue