From d2121bd5e6f9becef9ad4666053c92c5a13b301a Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 1 Mar 2020 20:26:16 +0100 Subject: [PATCH] rs: Add unorg-rs and showcase it in example.org. --- example/example.org | 20 ++++++++++++++++++++ rs.rkt | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/example/example.org b/example/example.org index 8e95eec..cf317b0 100644 --- a/example/example.org +++ b/example/example.org @@ -467,6 +467,26 @@ tab [[file:dots/examplehsuRqc.svg]] :END: +** Reaction systems + :PROPERTIES: + :header-args:racket: :prologue "#lang racket\n(require graph (file \"~/Candies/prj/racket/dds/rs.rkt\") (file \"~/Candies/prj/racket/dds/utils.rkt\"))" + :END: + Consider the following reaction system: + #+NAME: rs1 + | a | x t | y | z | + | b | x | q | z | + + Here is how we read this reaction into Racket code: + + #+BEGIN_SRC racket :results output drawer :var input-rs=munch-table(rs1) +(unorg-rs input-rs) + #+END_SRC + + #+RESULTS: + :RESULTS: + (hash 'a (reaction (set 'x 't) (set 'y) (set 'z)) 'b (reaction (set 'x) (set 'q) (set 'z))) + :END: + * Local Variables :noexport: # Local Variables: diff --git a/rs.rkt b/rs.rkt index 8075ac7..b6c573b 100644 --- a/rs.rkt +++ b/rs.rkt @@ -14,7 +14,9 @@ ;; Type names Species ReactionSystem ;; Functions - enabled? list-enabled union-products apply-rs ht-str-triples->rs) + enabled? list-enabled union-products apply-rs ht-str-triples->rs + ;; Syntax + unorg-rs) ;;; ================= ;;; Basic definitions @@ -95,3 +97,6 @@ (for/hash : ReactionSystem ([(a triple) (in-hash ht)]) (values a (str-triple->reaction triple)))) + +;;; Chains ht-str-triples->rs with unorg. +(define (unorg-rs str) (ht-str-triples->rs (unorg str)))