From 171147ad5e8d695acb2ef3318a439fa5c03a9ac4 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 2 Mar 2020 23:03:10 +0100 Subject: [PATCH] rs: Add read-context-sequence. --- rs-tests.rkt | 2 ++ rs.rkt | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/rs-tests.rkt b/rs-tests.rkt index 9d3b6ea..f827539 100644 --- a/rs-tests.rkt +++ b/rs-tests.rkt @@ -21,6 +21,8 @@ (test-case "Org-mode interaction" (check-equal? (ht-str-triples->rs #hash((a . ("x t" "y" "z")))) (make-immutable-hash (list (cons 'a (reaction (set 'x 't) (set 'y) (set 'z)))))) + (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"))))) diff --git a/rs.rkt b/rs.rkt index 5195c4d..eb6803c 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-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?))] [dds-step-one-annotated (-> dynamics? state? (set/c (cons/c (set/c symbol?) state?)))] @@ -102,6 +103,10 @@ ;;; Chains ht-str-triples->rs with unorg. (define-syntax-rule (unorg-rs str) (ht-str-triples->rs (unorg str))) +;;; Reads a context sequence from an Org sexp corresponding to a list. +(define (read-context-sequence str) + (map (compose list->set read-symbol-list) (flatten (read-org-sexp str)))) + ;;; Removes the first and the last symbol of a given string. (define (drop-first-last str) (substring str 1 (- (string-length str) 1)))