functions: Add read-org-sbfs.

This commit is contained in:
Sergiu Ivanov 2020-07-14 23:55:55 +02:00
parent 45e4feaee0
commit 17ffa3eb81

View file

@ -41,7 +41,8 @@
[tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))]
[tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))]
[sbf (-> (vectorof number?) tbf?)]
[list->sbf (-> (listof number?) sbf?)])
[list->sbf (-> (listof number?) sbf?)]
[read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))])
;; Predicates
(contract-out
[sbf? (-> any/c boolean?)]))
@ -391,3 +392,18 @@
(module+ test
(check-equal? (list->sbf '(1 -1)) (tbf '#(1 -1) 0)))
;;; Reads a list of SBF from an Org-mode string containing a sexp,
;;; containing a list of lists of numbers. If headers is #t, drops
;;; the first list, supposing that it contains the headers of the
;;; table.
;;;
;;; The input is typically what read-org-sexp reads.
(define (read-org-sbfs str #:headers [headers #f])
(define sexp (read-org-sexp str))
(define sexp-clean (cond [headers (cdr sexp)] [else sexp]))
(map list->sbf sexp-clean))
(module+ test
(check-equal? (read-org-sbfs "((1 1) (1 -1))")
(list (tbf '#(1 1) 0) (tbf '#(1 -1) 0))))