utils.rkt: Copy string->any.

This commit is contained in:
Sergiu Ivanov 2020-12-05 00:33:14 +01:00
parent 1273a9595f
commit 54905071d7
3 changed files with 19 additions and 3 deletions

View File

@ -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)))
]}
@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{Pretty printing}

View File

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

View File

@ -5,7 +5,7 @@
(provide Symbol VariableMapping
eval-with eval1-with
extract-symbols
any->string stringify-variable-mapping
any->string stringify-variable-mapping string->any
;; Syntax
auto-hash-ref/explicit auto-hash-ref/:)
@ -151,3 +151,12 @@
(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)")))
(: 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)))