From 4c6f3af2a92834617a90b7e23a94d3250efa4547 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Tue, 24 Mar 2020 21:31:01 +0100 Subject: [PATCH] rs: Add read-org-rs and define unorg-rs as a synonym for it. --- rs-tests.rkt | 8 +++++++- rs.rkt | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rs-tests.rkt b/rs-tests.rkt index 2c0ae5b..616a6ff 100644 --- a/rs-tests.rkt +++ b/rs-tests.rkt @@ -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))] diff --git a/rs.rkt b/rs.rkt index 38ecfdd..a151629 100644 --- a/rs.rkt +++ b/rs.rkt @@ -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)