rs: Add read-org-rs and define unorg-rs as a synonym for it.

This commit is contained in:
Sergiu Ivanov 2020-03-24 21:31:01 +01:00
parent 7f214266d0
commit 4c6f3af2a9
2 changed files with 13 additions and 3 deletions

View File

@ -24,7 +24,13 @@
(check-equal? (read-context-sequence "((\"x y\") (\"z\") (\"\") (\"t\"))")
(list (set 'x 'y) (set 'z) (set) (set 't)))
(check-equal? (rs->ht-str-triples (make-immutable-hash (list (cons 'a (reaction (set 'x 't) (set 'y) (set 'z))))))
#hash((a . ("t x" "y" "z")))))
#hash((a . ("t x" "y" "z"))))
(check-equal? (read-org-rs "((\"a\" \"x t\" \"y\" \"z\") (\"b\" \"x\" \"q\" \"z\"))")
(hash
'a
(reaction (set 'x 't) (set 'y) (set 'z))
'b
(reaction (set 'x) (set 'q) (set 'z)))))
(test-case "Dynamics of reaction systems"
(let* ([r1 (reaction (set 'x) (set 'y) (set 'z))]

8
rs.rkt
View File

@ -17,6 +17,7 @@
[union-products (-> reaction-system/c (listof symbol?) (set/c species?))]
[apply-rs (-> reaction-system/c (set/c species?) (set/c species?))]
[ht-str-triples->rs (-> (hash/c symbol? (list/c string? string? string?)) reaction-system/c)]
[read-org-rs (-> string? reaction-system/c)]
[read-context-sequence (-> string? (listof (set/c species?)))]
[rs->ht-str-triples (-> reaction-system/c (hash/c symbol? (list/c string? string? string?)))]
[dds-step-one (-> dynamics? state? (set/c state?))]
@ -103,8 +104,11 @@
(for/hash ([(a triple) (in-hash ht)])
(values a (str-triple->reaction triple))))
;;; Chains ht-str-triples->rs with read-org-variable-mapping.
(define-syntax-rule (unorg-rs str) (ht-str-triples->rs (read-org-variable-mapping str)))
;;; Reads a reaction system from an Org-mode style string.
(define read-org-rs (compose ht-str-triples->rs read-org-variable-mapping))
;;; A synonym for read-org-rs.
(define-syntax-rule (unorg-rs str) (read-org-rs str))
;;; Reads a context sequence from an Org sexp corresponding to a list.
(define (read-context-sequence str)