diff --git a/rs.rkt b/rs.rkt index 4165870..b49841c 100644 --- a/rs.rkt +++ b/rs.rkt @@ -5,7 +5,7 @@ (provide Species (struct-out reaction) Reaction - make-reaction) + make-reaction enabled?) (module+ test (require typed/rackunit)) @@ -26,6 +26,20 @@ (test-case "make-reaction" (check-equal? (make-reaction '(a b) '(c d) '(e f)) (reaction (set 'b 'a) (set 'c 'd) (set 'f 'e))))) + + (: enabled? (-> Reaction (Setof Species) Boolean)) + (define/match (enabled? r s) + [((reaction r i _) s) + (and (subset? r s) (set-empty? (set-intersect i s)))]) + + (module+ test + (test-case "enabled?" + (check-true (enabled? (make-reaction '(a b) '(c d) '()) + (set 'a 'b 'e))) + (check-false (enabled? (make-reaction '(a b) '(c d) '()) + (set 'a 'b 'c))) + (check-false (enabled? (make-reaction '(a b) '(c d) '()) + (set 'b 'e))))) ) (require graph "utils.rkt" "generic.rkt") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index b5e21d2..ed5d439 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -59,6 +59,20 @@ instead of set syntax. (make-reaction '(a b) '(c d) '(e f)) ]} +@defproc[(enabled? [r Reaction] [s (Setof Species)]) Boolean]{ + +A @racket[Reaction] is enabled on a set of species if all of its +reactants are in the set and none of its inhibitors are. + +@ex[ +(enabled? (make-reaction '(a b) '(c d) '()) + (set 'a 'b 'e)) +(enabled? (make-reaction '(a b) '(c d) '()) + (set 'a 'b 'c)) +(enabled? (make-reaction '(a b) '(c d) '()) + (set 'b 'e)) +]} + @section{Org-mode interaction} This section contains some useful primitives for