From d779c52cc828cd621e8ee700c7d6bfd7375619f4 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 9 Aug 2023 11:15:43 +0200 Subject: [PATCH] Type list-enabled. --- rs.rkt | 15 ++++++++++++++- scribblings/rs.scrbl | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/rs.rkt b/rs.rkt index 9daabc5..aa62ed5 100644 --- a/rs.rkt +++ b/rs.rkt @@ -5,7 +5,7 @@ (provide Species (struct-out reaction) Reaction ReactionSystem - make-reaction enabled?) + make-reaction enabled? list-enabled) (module+ test (require typed/rackunit)) @@ -42,6 +42,19 @@ (set 'b 'e))))) (define-type ReactionSystem (HashTable Symbol Reaction)) + + (: list-enabled (-> ReactionSystem (Setof Species) (Listof Symbol))) + (define (list-enabled rs s) + (for/list ([(name reaction) (in-hash rs)] + #:when (enabled? reaction s)) + name)) + + (module+ test + (test-case "list-enabled" + (define rs (hash 'a (make-reaction '(x) '(y) '(z)) + 'b (make-reaction '(x y) '() '(z)))) + (check-equal? (list-enabled rs (set 'x 'y)) '(b)) + (check-equal? (list-enabled rs (set 'x)) '(a)))) ) (require graph "utils.rkt" "generic.rkt") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index 8b209b9..05007e4 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -80,6 +80,19 @@ A reaction system is a dictionary mapping reaction names } +@defproc[(list-enabled [rs ReactionSystem] [s (Setof Species)]) (Listof Symbol)]{ + +Returns the list of the names of reactions of @racket[rs] enabled on +@racket[s]. + +@ex[ +(let ([rs (hash 'a (make-reaction '(x) '(y) '(z)) + 'b (make-reaction '(x y) '() '(z)))]) + (values (list-enabled rs (set 'x 'y)) + (list-enabled rs (set 'x)))) +]} + + @section{Org-mode interaction}