Type list-enabled.
This commit is contained in:
parent
cf9a68ae6b
commit
d779c52cc8
2 changed files with 27 additions and 1 deletions
15
rs.rkt
15
rs.rkt
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
Species (struct-out reaction) Reaction ReactionSystem
|
Species (struct-out reaction) Reaction ReactionSystem
|
||||||
make-reaction enabled?)
|
make-reaction enabled? list-enabled)
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require typed/rackunit))
|
(require typed/rackunit))
|
||||||
|
@ -42,6 +42,19 @@
|
||||||
(set 'b 'e)))))
|
(set 'b 'e)))))
|
||||||
|
|
||||||
(define-type ReactionSystem (HashTable Symbol Reaction))
|
(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")
|
(require graph "utils.rkt" "generic.rkt")
|
||||||
|
|
|
@ -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}
|
@section{Org-mode interaction}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue