diff --git a/utils-tests.rkt b/utils-tests.rkt index bb4be65..431b7ca 100644 --- a/utils-tests.rkt +++ b/utils-tests.rkt @@ -47,4 +47,6 @@ (check-equal? (string->any "(or b (not a))") '(or b (not a))) (check-equal? (string->any "14") 14) (check-equal? (read-org-table "((\"a\" \"(and a b)\") (\"b\" \"(or b (not a))\"))") - '(("a" "(and a b)") ("b" "(or b (not a))")))) + '(("a" "(and a b)") ("b" "(or b (not a))"))) + (check-equal? (unstringify-pairs '(("a" . "1") ("b" . "(and a (not b))"))) + '((a . 1) (b . (and a (not b)))))) diff --git a/utils.rkt b/utils.rkt index 3c736c7..a600a28 100644 --- a/utils.rkt +++ b/utils.rkt @@ -14,7 +14,8 @@ [any->string (-> any/c string?)] [stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)] [string->any (-> string? any/c)] - [read-org-table (-> string? (listof any/c))]) + [read-org-table (-> string? (listof any/c))] + [unstringify-pairs (-> (listof (cons/c string? string?)) (listof (cons/c symbol? any/c)))]) ;; Contracts (contract-out [variable-mapping? contract?] [string-variable-mapping? contract?]) @@ -172,3 +173,11 @@ ;;; Reads a table from a string produced by Org-mode for a named ;;; table. See example.org for examples. (define (read-org-table str) (string->any str)) + +;;; Given a list of pairs of strings, converts the first element of +;;; each pair to a string, and reads the second element with +;;; string->any. +(define (unstringify-pairs pairs) + (for/list ([p pairs]) + (match-let ([(cons key val) p]) + (cons (string->symbol key) (string->any val)))))