Type read-context-sequence.

This commit is contained in:
Sergiu Ivanov 2023-08-11 15:55:09 +02:00
parent 6a9adf5e07
commit c1723066a7
2 changed files with 20 additions and 1 deletions

12
rs.rkt
View File

@ -7,7 +7,7 @@
Species (struct-out reaction) Reaction ReactionName ReactionSystem
make-reaction enabled? list-enabled union-products apply-rs
str-triple->reaction ht-str-triples->rs read-org-rs
str-triple->reaction ht-str-triples->rs read-org-rs read-context-sequence
)
(module+ test
@ -133,6 +133,16 @@
(read-org-rs "((\"a\" \"x t\" \"y\" \"z\") (\"b\" \"x\" \"q\" \"z\"))")
(hash 'a (reaction (set 't 'x) (set 'y) (set 'z))
'b (reaction (set 'x) (set 'q) (set 'z))))))
(: read-context-sequence (-> String (Listof (Setof Species))))
(define (read-context-sequence str)
(for/list ([sexp (in-list (flatten (string->any str)))])
(list->set (read-symbol-list (assert-type sexp String)))))
(module+ test
(test-case "read-context-sequence"
(check-equal? (read-context-sequence "((\"x y\") (\"z\") (\"\") (\"t\"))")
(list (set 'x 'y) (set 'z) (set) (set 't)))))
)
(require graph "utils.rkt" "generic.rkt")

View File

@ -156,6 +156,15 @@ Reads a reaction system from an Org-mode style string.
(read-org-rs "((\"a\" \"x t\" \"y\" \"z\") (\"b\" \"x\" \"q\" \"z\"))")
]}
@defproc[(read-context-sequence [str String]) (Listof (Setof Species))]{
Reads a context sequence (a list of sets of species) from a string
containing a list, which may be produced by Org-mode.
@ex[
(read-context-sequence "((\"x y\") (\"z\") (\"\") (\"t\"))")
]}
@section{Dynamics of reaction systems}