utils.rkt: Copy string->any.
This commit is contained in:
parent
1273a9595f
commit
54905071d7
3 changed files with 19 additions and 3 deletions
|
@ -147,6 +147,14 @@ Converts all the values of a @racket[VariableMapping] to string.
|
||||||
(stringify-variable-mapping (hash 'a '(and a b) 'b '(not b)))
|
(stringify-variable-mapping (hash 'a '(and a b) 'b '(not b)))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(string->any [str String]) Any]{
|
||||||
|
|
||||||
|
Reads any value from string.
|
||||||
|
|
||||||
|
@examples[#:eval utils-evaluator
|
||||||
|
(string->any "(or b (not a))")
|
||||||
|
]}
|
||||||
|
|
||||||
@section{Additional graph utilities}
|
@section{Additional graph utilities}
|
||||||
|
|
||||||
@section{Pretty printing}
|
@section{Pretty printing}
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
;; Functions
|
;; Functions
|
||||||
(contract-out [string->any (-> string? any/c)]
|
(contract-out [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))]
|
||||||
[unstringify-pairs (-> (listof (general-pair/c string? any/c))
|
[unstringify-pairs (-> (listof (general-pair/c string? any/c))
|
||||||
|
|
11
utils.rkt
11
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 stringify-variable-mapping
|
any->string stringify-variable-mapping string->any
|
||||||
;; Syntax
|
;; Syntax
|
||||||
auto-hash-ref/explicit auto-hash-ref/:)
|
auto-hash-ref/explicit auto-hash-ref/:)
|
||||||
|
|
||||||
|
@ -151,3 +151,12 @@
|
||||||
(define mp (stringify-variable-mapping #hash((a . (and a b)) (b . (not b)))))
|
(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 'a) "(and a b)")
|
||||||
(check-equal? (hash-ref mp 'b) "(not b)")))
|
(check-equal? (hash-ref mp 'b) "(not b)")))
|
||||||
|
|
||||||
|
(: string->any (-> String Any))
|
||||||
|
(define (string->any str)
|
||||||
|
(with-input-from-string str (λ () (read))))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "string->any"
|
||||||
|
(check-equal? (string->any "(or b (not a))") '(or b (not a)))
|
||||||
|
(check-equal? (string->any "14") 14)))
|
||||||
|
|
Loading…
Reference in a new issue