From c1723066a7499dfdddca35f089bb6f51ff83c39f Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 11 Aug 2023 15:55:09 +0200 Subject: [PATCH] Type read-context-sequence. --- rs.rkt | 12 +++++++++++- scribblings/rs.scrbl | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rs.rkt b/rs.rkt index 8d8639e..0e6c477 100644 --- a/rs.rkt +++ b/rs.rkt @@ -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") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index 243e9e1..ce06256 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -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}