Add and use ReactionName.

This commit is contained in:
Sergiu Ivanov 2023-08-09 11:29:09 +02:00
parent d779c52cc8
commit 064169f0b6
2 changed files with 15 additions and 6 deletions

8
rs.rkt
View File

@ -4,7 +4,7 @@
(require typed/graph "utils.rkt" "dynamics.rkt") (require typed/graph "utils.rkt" "dynamics.rkt")
(provide (provide
Species (struct-out reaction) Reaction ReactionSystem Species (struct-out reaction) Reaction ReactionName ReactionSystem
make-reaction enabled? list-enabled) make-reaction enabled? list-enabled)
(module+ test (module+ test
@ -18,6 +18,8 @@
#:transparent #:transparent
#:type-name Reaction) #:type-name Reaction)
(define-type ReactionName Symbol)
(: make-reaction (-> (Listof Species) (Listof Species) (Listof Species) Reaction)) (: make-reaction (-> (Listof Species) (Listof Species) (Listof Species) Reaction))
(define (make-reaction r i p) (reaction (list->set r) (define (make-reaction r i p) (reaction (list->set r)
(list->set i) (list->set i)
@ -41,9 +43,9 @@
(check-false (enabled? (make-reaction '(a b) '(c d) '()) (check-false (enabled? (make-reaction '(a b) '(c d) '())
(set 'b 'e))))) (set 'b 'e)))))
(define-type ReactionSystem (HashTable Symbol Reaction)) (define-type ReactionSystem (HashTable ReactionName Reaction))
(: list-enabled (-> ReactionSystem (Setof Species) (Listof Symbol))) (: list-enabled (-> ReactionSystem (Setof Species) (Listof ReactionName)))
(define (list-enabled rs s) (define (list-enabled rs s)
(for/list ([(name reaction) (in-hash rs)] (for/list ([(name reaction) (in-hash rs)]
#:when (enabled? reaction s)) #:when (enabled? reaction s))

View File

@ -47,6 +47,12 @@ The type of the instances of @racket[reaction].
} }
@deftype[ReactionName]{
A reaction name is any @racket[Symbol].
}
@defproc[(make-reaction [r (Listof Reaction)] @defproc[(make-reaction [r (Listof Reaction)]
[i (Listof Reaction)] [i (Listof Reaction)]
[p (Listof Reaction)]) [p (Listof Reaction)])
@ -75,12 +81,13 @@ reactants are in the set and none of its inhibitors are.
@deftype[ReactionSystem]{ @deftype[ReactionSystem]{
A reaction system is a dictionary mapping reaction names A reaction system is a dictionary mapping @racket[ReactionName]s to
(@racket[Symbol]s) to @racket[Reaction]s. @racket[Reaction]s.
} }
@defproc[(list-enabled [rs ReactionSystem] [s (Setof Species)]) (Listof Symbol)]{ @defproc[(list-enabled [rs ReactionSystem] [s (Setof Species)])
(Listof ReactionName)]{
Returns the list of the names of reactions of @racket[rs] enabled on Returns the list of the names of reactions of @racket[rs] enabled on
@racket[s]. @racket[s].