diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 162d7c2..74e4252 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -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} diff --git a/utils-untyped.rkt b/utils-untyped.rkt index 5382214..77cb35a 100644 --- a/utils-untyped.rkt +++ b/utils-untyped.rkt @@ -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)) diff --git a/utils.rkt b/utils.rkt index be90701..dc80376 100644 --- a/utils.rkt +++ b/utils.rkt @@ -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)))