diff --git a/rs.rkt b/rs.rkt index ac2d996..3111a69 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 + str-triple->reaction ht-str-triples->rs ) (module+ test @@ -106,6 +106,20 @@ (test-case "str-triple->reaction" (check-equal? (str-triple->reaction '("a b" "c d" "e f")) (reaction (set 'b 'a) (set 'c 'd) (set 'f 'e))))) + + (: ht-str-triples->rs (-> (HashTable ReactionName (List String String String)) + ReactionSystem)) + (define (ht-str-triples->rs ht) + (for/hash : (HashTable ReactionName Reaction) + ([(a triple) (in-hash ht)]) + (values a (str-triple->reaction triple)))) + + (module+ test + (test-case "ht-str-triples->rs" + (check-equal? (ht-str-triples->rs (hash 'a (list "x y" "" "k i") + '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)))))) ) (require graph "utils.rkt" "generic.rkt") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index a5278eb..abd9325 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -137,6 +137,17 @@ Converts a triple of strings to a reaction. (str-triple->reaction '("a b" "c d" "e f")) ]} +@defproc[(ht-str-triples->rs [ht (HashTable ReactionName (List String String String))]) + ReactionSystem]{ + +Converts a hash table mapping reaction names to triples of strings to +a reaction system. + +@ex[ +(ht-str-triples->rs (hash 'a (list "x y" "" "k i") + 'b (list "" "x y" "t j"))) +]} + @section{Dynamics of reaction systems}