From 5c13b468e30d51316667a1ca83d3a219eb76c694 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 1 Mar 2020 19:51:53 +0100 Subject: [PATCH] rs: Add apply-rs. --- rs-tests.rkt | 4 +++- rs.rkt | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rs-tests.rkt b/rs-tests.rkt index d7347e9..b185221 100644 --- a/rs-tests.rkt +++ b/rs-tests.rkt @@ -14,4 +14,6 @@ (check-false (enabled? r1 s2)) (check-equal? (list-enabled rs s1) '(a b)) (check-equal? (list-enabled rs s2) '(b)) - (check-equal? (union-products rs '(a b)) (set 'y 'z)))) + (check-equal? (union-products rs '(a b)) (set 'y 'z)) + (check-equal? (apply-rs rs s1) (set 'y 'z)) + (check-equal? (apply-rs rs s2) (set 'y)))) diff --git a/rs.rkt b/rs.rkt index 8bb6c39..23a78d7 100644 --- a/rs.rkt +++ b/rs.rkt @@ -10,7 +10,7 @@ ;; Type names Species ReactionSystem ;; Functions - enabled? list-enabled union-products) + enabled? list-enabled union-products apply-rs) ;;; ================= ;;; Basic definitions @@ -55,3 +55,9 @@ ((inst set Species)) ; set-union requires at least one argument (for/list : (Listof (Setof Species)) ([a as]) (reaction-products (hash-ref rs a))))) + +;;; Applies a reaction system to a set. +(: apply-rs (-> ReactionSystem (Setof Species) (Setof Species))) +(define (apply-rs rs s) + (let ([as (list-enabled rs s)]) + (union-products rs as)))