utils: Type handle-org-booleans.
This commit is contained in:
parent
9d569bd3ba
commit
b6417d2d07
1 changed files with 23 additions and 14 deletions
37
utils.rkt
37
utils.rkt
|
@ -15,7 +15,8 @@
|
||||||
(for-syntax syntax/parse racket/list))
|
(for-syntax syntax/parse racket/list))
|
||||||
|
|
||||||
(provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
(provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
||||||
extract-symbols any->string stringify-variable-mapping string->any)
|
extract-symbols any->string stringify-variable-mapping string->any
|
||||||
|
handle-org-booleans)
|
||||||
|
|
||||||
(define-type Variable Symbol)
|
(define-type Variable Symbol)
|
||||||
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
||||||
|
@ -150,6 +151,27 @@
|
||||||
(test-case "string->any"
|
(test-case "string->any"
|
||||||
(check-equal? (string->any "(or b (not a))") '(or b (not a)))
|
(check-equal? (string->any "(or b (not a))") '(or b (not a)))
|
||||||
(check-equal? (string->any "14") 14)))
|
(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
|
||||||
|
;;; prin1 because the Elisp sexps seems incompatible with Racket.
|
||||||
|
;;; On the other hand, Racket Booleans seem to upset Elisp a little,
|
||||||
|
;;; so prin1 wraps them in additional double quotes. This function
|
||||||
|
;;; removes those quotes.
|
||||||
|
(: handle-org-booleans (-> Any Any))
|
||||||
|
(define/match (handle-org-booleans datum)
|
||||||
|
[("#t") #t]
|
||||||
|
[("#f") #f]
|
||||||
|
[((? list?)) (map handle-org-booleans datum)]
|
||||||
|
[ (_) datum])
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "handle-org-booleans"
|
||||||
|
(check-equal? (handle-org-booleans "#t") #t)
|
||||||
|
(check-equal? (handle-org-booleans "#f") #f)
|
||||||
|
(check-equal? (handle-org-booleans '("#t" "#f")) '(#t #f))
|
||||||
|
(check-equal? (handle-org-booleans "t") "t")))
|
||||||
)
|
)
|
||||||
|
|
||||||
(require 'typed)
|
(require 'typed)
|
||||||
|
@ -210,19 +232,6 @@
|
||||||
;;; A string variable mapping is a mapping from variables to strings.
|
;;; A string variable mapping is a mapping from variables to strings.
|
||||||
(define (string-variable-mapping? dict) (hash/c symbol? string?))
|
(define (string-variable-mapping? dict) (hash/c symbol? string?))
|
||||||
|
|
||||||
;;; 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
|
|
||||||
;;; prin1 because the elisp sexp seems incompatible with Racket. On
|
|
||||||
;;; the other hand, Racket Booleans seem to upset elisp a little, so
|
|
||||||
;;; prin1 wraps them in additional double quotes. This function
|
|
||||||
;;; removes those quotes.
|
|
||||||
(define/match (handle-org-booleans datum)
|
|
||||||
[("#t") #t]
|
|
||||||
[("#f") #f]
|
|
||||||
[((? list?)) (map handle-org-booleans datum)]
|
|
||||||
[ (_) datum])
|
|
||||||
|
|
||||||
;;; Given a sexp, applies the given function to any object which is
|
;;; Given a sexp, applies the given function to any object which is
|
||||||
;;; not a list.
|
;;; not a list.
|
||||||
;;;
|
;;;
|
||||||
|
|
Loading…
Reference in a new issue