From 6a9adf5e072e73836e6ac4276ffd7c4c980c1618 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Thu, 10 Aug 2023 18:05:22 +0200 Subject: [PATCH] Type read-org-rs. --- rs.rkt | 15 ++++++++++++++- scribblings/rs.scrbl | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rs.rkt b/rs.rkt index 3111a69..8d8639e 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 + str-triple->reaction ht-str-triples->rs read-org-rs ) (module+ test @@ -120,6 +120,19 @@ 'b (list "" "x y" "t j"))) (hash 'a (reaction (set 'y 'x) (set) (set 'k 'i)) 'b (reaction (set) (set 'y 'x) (set 't 'j)))))) + + (: read-org-rs (-> String ReactionSystem)) + (define (read-org-rs str) + (ht-str-triples->rs + (assert-type (read-org-variable-mapping str) + (Immutable-HashTable ReactionName (List String String String))))) + + (module+ test + (test-case "read-org-rs" + (check-equal? + (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)))))) ) (require graph "utils.rkt" "generic.rkt") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index abd9325..243e9e1 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -148,6 +148,14 @@ a reaction system. 'b (list "" "x y" "t j"))) ]} +@defproc[(read-org-rs [str String]) ReactionSystem]{ + +Reads a reaction system from an Org-mode style string. + +@ex[ +(read-org-rs "((\"a\" \"x t\" \"y\" \"z\") (\"b\" \"x\" \"q\" \"z\"))") +]} + @section{Dynamics of reaction systems}