rs: Add section "Org-mode interaction".

This commit is contained in:
Sergiu Ivanov 2020-03-01 20:20:16 +01:00
parent a77261c424
commit f16747d157

34
rs.rkt
View file

@ -4,13 +4,16 @@
;;; Definitions for working with reaction systems.
(require/typed "utils.rkt"
[string->any (String -> Any)])
(provide
;; Structures
reaction
;; Type names
Species ReactionSystem
;; Functions
enabled? list-enabled union-products apply-rs)
enabled? list-enabled union-products apply-rs ht-str-triples->rs)
;;; =================
;;; Basic definitions
@ -62,3 +65,32 @@
(define (apply-rs rs s)
(let ([as (list-enabled rs s)])
(union-products rs as)))
;;; ====================
;;; Org-mode interaction
;;; ====================
;;; This section contains some useful primitives for interoperating
;;; with org-mode.
;;; Reads a list of species from a string.
(: read-symbol-list (-> String (Listof Species)))
(define (read-symbol-list str)
(cast (string->any (string-append "(" str ")")) (Listof Species)))
;;; Converts a triple of strings to a reaction.
(: str-triple->reaction (-> (List String String String) reaction))
(define/match (str-triple->reaction lst)
[((list str-reactants str-inhibitors str-products))
(reaction (list->set (read-symbol-list str-reactants))
(list->set (read-symbol-list str-inhibitors))
(list->set (read-symbol-list str-products)))])
;;; Converts a hash table mapping reaction names to triples of strings
;;; to a reaction system.
(: ht-str-triples->rs (-> (HashTable Symbol (List String String String)) ReactionSystem))
(define (ht-str-triples->rs ht)
(for/hash : ReactionSystem
([(a triple) (in-hash ht)])
(values a (str-triple->reaction triple))))