From a469eae764e6088267d7401a96f22eeeb113bbed Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 13 Aug 2023 21:17:32 +0200 Subject: [PATCH] Type reaction->str-triple. --- rs.rkt | 12 ++++++++++++ scribblings/rs.scrbl | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/rs.rkt b/rs.rkt index 0e6c477..53d1f5f 100644 --- a/rs.rkt +++ b/rs.rkt @@ -8,6 +8,7 @@ make-reaction enabled? list-enabled union-products apply-rs str-triple->reaction ht-str-triples->rs read-org-rs read-context-sequence + reaction->str-triple ) (module+ test @@ -143,6 +144,17 @@ (test-case "read-context-sequence" (check-equal? (read-context-sequence "((\"x y\") (\"z\") (\"\") (\"t\"))") (list (set 'x 'y) (set 'z) (set) (set 't))))) + + (: reaction->str-triple (-> Reaction (Listof String))) + (define/match (reaction->str-triple r) + [((reaction r i p)) + (for/list ([c (in-list (list r i p))]) + (drop-first-last (any->string (set->list c))))]) + + (module+ test + (test-case "reaction->str-triple" + (check-equal? (reaction->str-triple (make-reaction '(x y) '(z t) '(k i))) + '("x y" "z t" "i k")))) ) (require graph "utils.rkt" "generic.rkt") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index ce06256..2188c61 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -165,6 +165,14 @@ containing a list, which may be produced by Org-mode. (read-context-sequence "((\"x y\") (\"z\") (\"\") (\"t\"))") ]} +@defproc[(reaction->str-triple [r Reaction]) (Listof String)]{ + +Converts a reaction to a triple of strings. + +@ex[ +(reaction->str-triple (make-reaction '(x y) '(z t) '(k i))) +]} + @section{Dynamics of reaction systems}