utils: Add string->any.

This commit is contained in:
Sergiu Ivanov 2020-02-22 12:11:37 +01:00
parent e37aeca9e7
commit 1eb48bc5e2
2 changed files with 9 additions and 2 deletions

View file

@ -43,4 +43,6 @@
(check-equal? (hash-ref mp 'b) "(not b)"))
(let ([mp (sgfy #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)")))
(check-equal? (hash-ref mp 'b) "(not b)"))
(check-equal? (string->any "(or b (not a))") '(or b (not a)))
(check-equal? (string->any "14") 14))

View file

@ -12,7 +12,8 @@
(contract-out [eval-with (-> variable-mapping? any/c any)]
[extract-symbols (-> any/c list?)]
[any->string (-> any/c string?)]
[variable-mapping-stringify (-> variable-mapping? string-variable-mapping?)])
[variable-mapping-stringify (-> variable-mapping? string-variable-mapping?)]
[string->any (-> string? any/c)])
;; Contracts
(contract-out [variable-mapping? contract?]
[string-variable-mapping? contract?])
@ -162,3 +163,7 @@
;;; A shortcut for variable-mapping-stingify.
(define-syntax-rule (sgfy ht) (variable-mapping-stringify ht))
;;; Reads any value from string.
(define (string->any str)
(with-input-from-string str (λ () (read))))