Type read-org-tbfs/state and add read-org-tbfs/state+headers.
This commit is contained in:
parent
b611115f8c
commit
495ea18bb5
2 changed files with 51 additions and 0 deletions
|
@ -174,3 +174,29 @@ the thresholds are set to 0.
|
|||
(lists+headers->sbfs/state '((x y) (1 2) (1 1)))
|
||||
(lists->sbfs/state '((1 2) (1 1)))
|
||||
]}
|
||||
|
||||
@defproc[(read-org-tbfs/state [str String]) (Listof TBF/State)]{
|
||||
|
||||
Reads a list of @racket[TBF/State] from an Org-mode string containing
|
||||
a sexp, containing a list of lists of numbers. As in
|
||||
@racket[lists->tbfs/state], the last element of each list is taken to
|
||||
be the threshold of the TBF, and the rest of the elements are taken to
|
||||
be the weights.
|
||||
|
||||
Similarly to @racket[lists->tbfs/state], the names of the variables
|
||||
are generated as @tt{xi}, where @italic{i} is the index of the
|
||||
variable, starting from 0.
|
||||
|
||||
@ex[
|
||||
(read-org-tbfs/state "((1 2 3) (1 1 2))")
|
||||
]}
|
||||
|
||||
@defproc[(read-org-tbfs/state+headers [str String]) (Listof TBF/State)]{
|
||||
|
||||
Like @racket[read-org-tbfs/state], but the first list in @racket[str]
|
||||
is taken to contain the names of the variables, similarly to
|
||||
@racket[lists+headers->tbfs/state].
|
||||
|
||||
@ex[
|
||||
(read-org-tbfs/state+headers "((a b f) (1 2 3) (1 1 2))")
|
||||
]}
|
||||
|
|
25
tbn.rkt
25
tbn.rkt
|
@ -27,6 +27,7 @@
|
|||
|
||||
lists+vars->tbfs/state lists+headers->tbfs/state lists->tbfs/state
|
||||
lists+vars->sbfs/state lists+headers->sbfs/state lists->sbfs/state
|
||||
read-org-tbfs/state read-org-tbfs/state+headers
|
||||
)
|
||||
|
||||
(: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One)))
|
||||
|
@ -156,6 +157,30 @@
|
|||
(list
|
||||
(tbf/state '#hash((x0 . 1) (x1 . 2)) 0)
|
||||
(tbf/state '#hash((x0 . 1) (x1 . 1)) 0)))))
|
||||
|
||||
(: read-org-tbfs/state (-> String (Listof TBF/State)))
|
||||
(define (read-org-tbfs/state str)
|
||||
(lists->tbfs/state
|
||||
(assert-type (read-org-sexp str)
|
||||
(Listof (Listof Real)))))
|
||||
|
||||
(module+ test
|
||||
(test-case "read-org-tbfs/state"
|
||||
(check-equal? (read-org-tbfs/state "((1 2 3) (1 1 2))")
|
||||
(list (tbf/state '#hash((x0 . 1) (x1 . 2)) 3)
|
||||
(tbf/state '#hash((x0 . 1) (x1 . 1)) 2)))))
|
||||
|
||||
(: read-org-tbfs/state+headers (-> String (Listof TBF/State)))
|
||||
(define (read-org-tbfs/state+headers str)
|
||||
(lists+headers->tbfs/state
|
||||
(assert-type (read-org-sexp str)
|
||||
(Pairof (Listof Variable) (Listof (Listof Real))))))
|
||||
|
||||
(module+ test
|
||||
(test-case "read-org-tbfs/state+headers"
|
||||
(check-equal? (read-org-tbfs/state+headers "((a b f) (1 2 3) (1 1 2))")
|
||||
(list (tbf/state '#hash((a . 1) (b . 2)) 3)
|
||||
(tbf/state '#hash((a . 1) (b . 1)) 2)))))
|
||||
)
|
||||
|
||||
(module+ test
|
||||
|
|
Loading…
Reference in a new issue