utils: Generalise unstringify-pairs to accept both proper and improper pairs.

This commit is contained in:
Sergiu Ivanov 2020-02-22 18:58:19 +01:00
parent 5b4d39a1b0
commit a2b8df2a67

View file

@ -15,7 +15,7 @@
[stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)] [stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)]
[string->any (-> string? any/c)] [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)))]) [unstringify-pairs (-> (listof (list/c string? string?)) (listof (list/c symbol? any/c)))])
;; Contracts ;; Contracts
(contract-out [variable-mapping? contract?] (contract-out [variable-mapping? contract?]
[string-variable-mapping? contract?]) [string-variable-mapping? contract?])
@ -179,5 +179,8 @@
;;; string->any. ;;; string->any.
(define (unstringify-pairs pairs) (define (unstringify-pairs pairs)
(for/list ([p pairs]) (for/list ([p pairs])
(match-let ([(cons key val) p]) (match p
(cons (string->symbol key) (string->any val))))) [(list key val)
(cons (string->symbol key) (string->any val))]
[(cons key val) ; also handle improper pairs
(cons (string->symbol key) (string->any val))])))