Type ht-str-triples->rs.

This commit is contained in:
Sergiu Ivanov 2023-08-10 16:46:32 +02:00
parent e884a2ee07
commit aae2e1f964
2 changed files with 26 additions and 1 deletions

16
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
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")

View file

@ -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}