Type read-org-sbfs.

This commit is contained in:
Sergiu Ivanov 2022-04-25 23:43:25 +02:00
parent ef979d6dce
commit 974bf193ed
2 changed files with 28 additions and 37 deletions

View File

@ -31,7 +31,7 @@
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean
list->tbf lists->tbfs read-org-tbfs tbf-tabulate* tbf-tabulate
tbf-tabulate*/boolean sbf? sbf list->sbf)
tbf-tabulate*/boolean sbf? sbf list->sbf read-org-sbfs)
(module+ test
(require typed/rackunit))
@ -563,6 +563,17 @@
(test-case "list->sbf"
(check-equal? (list->sbf '(1 -1)) (tbf '#(1 -1) 0))))
(: read-org-sbfs (->* (String) (#:headers Boolean) (Listof tbf)))
(define (read-org-sbfs str #:headers [headers #f])
(define sexp (assert-type (read-org-sexp str) (Listof Any)))
(define sexp-clean (cond [headers (cdr sexp)] [else sexp]))
(map list->sbf (assert-type sexp-clean (Listof (Listof Real)))))
(module+ test
(test-case "read-org-sbfs"
(check-equal? (read-org-sbfs "((1 1) (1 -1))")
(list (tbf '#(1 1) 0) (tbf '#(1 -1) 0)))))
(module untyped racket
(module+ test
(require rackunit))
@ -653,39 +664,4 @@
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean
list->tbf lists->tbfs read-org-tbfs tbf-tabulate* tbf-tabulate
tbf-tabulate*/boolean sbf? sbf list->sbf)
(require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped]
[tabulate* tabulate*/untyped]))
(provide
;; Functions
(contract-out
[read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))]))
(module+ test
(require rackunit))
;;; ===========================
;;; Threshold Boolean functions
;;; ===========================
;;; 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
(test-case "read-org-sbfs"
(check-equal? (read-org-sbfs "((1 1) (1 -1))")
(list (tbf '#(1 1) 0) (tbf '#(1 -1) 0)))))
tbf-tabulate*/boolean sbf? sbf list->sbf read-org-sbfs)

View File

@ -592,6 +592,21 @@ the weights of the SBF.
(list->sbf '(1 -1))
]}
@defproc[(read-org-sbfs [str String] [#:headers headers Boolean #f])
(Listof tbf)]{
Reads a list of SBF from an Org-mode string containing a sexp, containing
a list of lists of numbers. If headers is @racket[#t], drops the first list,
supposing that it contains the headers of the table.
The input is typically what @racket[read-org-sexp] reads.
@ex[
(read-org-sbfs "((1 1) (1 -1))")
]
See also @racket[read-org-tbfs].
}
@section[#:tag "fuctions/untyped"]{Untyped definitions}
@defmodule[(submod dds/functions typed untyped)]