diff --git a/rs.rkt b/rs.rkt index 70200c3..37ec509 100644 --- a/rs.rkt +++ b/rs.rkt @@ -5,7 +5,7 @@ (provide Species (struct-out reaction) Reaction ReactionName ReactionSystem - make-reaction enabled? list-enabled union-products) + make-reaction enabled? list-enabled union-products apply-rs) (module+ test (require typed/rackunit)) @@ -77,6 +77,20 @@ (set 'z)) (check-equal? (union-products rs '()) (set)))) + + (: apply-rs (-> ReactionSystem (Setof Species) (Setof Species))) + (define (apply-rs rs s) + (let ([as (list-enabled rs s)]) + (union-products rs as))) + + (module+ test + (test-case "apply-rs" + (define rs (hash 'a (make-reaction '(x) '(y) '(z)) + 'b (make-reaction '(x y) '() '(t)))) + (check-equal? (apply-rs rs (set 'x 'y)) + (set 't)) + (check-equal? (apply-rs rs (set 'x)) + (set 'z)))) ) (require graph "utils.rkt" "generic.rkt") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index 6f733a5..3ebaf6f 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -112,6 +112,17 @@ empty set. '(a b)) ]} +@defproc[(apply-rs [rs ReactionSystem] [s (Setof Species)]) + (Setof Species)]{ + +Applies the reaction system @racket[rs] to @racket[s]. + +@ex[ +(let ([rs (hash 'a (make-reaction '(x) '(y) '(z)) + 'b (make-reaction '(x y) '() '(z)))]) + (apply-rs rs (set 'x))) +]} + @section{Org-mode interaction}