utils: Type string->any.
This commit is contained in:
parent
783000318b
commit
9d569bd3ba
2 changed files with 20 additions and 13 deletions
|
@ -156,6 +156,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}
|
||||
|
|
25
utils.rkt
25
utils.rkt
|
@ -15,7 +15,7 @@
|
|||
(for-syntax syntax/parse racket/list))
|
||||
|
||||
(provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
||||
extract-symbols any->string stringify-variable-mapping)
|
||||
extract-symbols any->string stringify-variable-mapping string->any)
|
||||
|
||||
(define-type Variable Symbol)
|
||||
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
||||
|
@ -141,18 +141,26 @@
|
|||
(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)))
|
||||
)
|
||||
|
||||
(require 'typed)
|
||||
(provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
||||
extract-symbols any->string stringify-variable-mapping)
|
||||
extract-symbols any->string stringify-variable-mapping string->any)
|
||||
|
||||
;;; Untyped section.
|
||||
|
||||
(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))
|
||||
|
@ -202,15 +210,6 @@
|
|||
;;; A string variable mapping is a mapping from variables to strings.
|
||||
(define (string-variable-mapping? dict) (hash/c symbol? string?))
|
||||
|
||||
;;; Reads any value from string.
|
||||
(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)))
|
||||
|
||||
;;; Given a sexp, converts all "#f" to #f and "#t" to #t.
|
||||
;;;
|
||||
;;; When I read Org-mode tables, I pump them through a call to the
|
||||
|
|
Loading…
Reference in a new issue