From c0d36a34a7bef67af83294d32091853ec9fdd7c2 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 2 Mar 2020 23:11:26 +0100 Subject: [PATCH] rs: Add read-ctx and illustrate it in example.org. --- example/example.org | 16 ++++++++++++++++ rs.rkt | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/example/example.org b/example/example.org index 14895ad..4c90cb1 100644 --- a/example/example.org +++ b/example/example.org @@ -519,6 +519,22 @@ tab - a - b + You can also give a name to a list and read it with =munch-sexp=: + + #+NAME: ctx1 + - x y + - z + - + - t + + #+BEGIN_SRC racket :results output drawer :var input-ctx=munch-sexp(ctx1) +(read-ctx input-ctx) + #+END_SRC + + #+RESULTS: + :RESULTS: + (list (set 'x 'y) (set 'z) (set) (set 't)) + :END: * Local Variables :noexport: # Local Variables: diff --git a/rs.rkt b/rs.rkt index eb6803c..c1005af 100644 --- a/rs.rkt +++ b/rs.rkt @@ -31,7 +31,7 @@ ;; Contracts (contract-out [reaction-system/c contract?]) ;; Syntax - unorg-rs org-rs) + unorg-rs org-rs read-ctx) ;;; ================= ;;; Basic definitions @@ -107,6 +107,9 @@ (define (read-context-sequence str) (map (compose list->set read-symbol-list) (flatten (read-org-sexp str)))) +;;; A shortcut to read-context-sequence. +(define-syntax-rule (read-ctx str) (read-context-sequence str)) + ;;; Removes the first and the last symbol of a given string. (define (drop-first-last str) (substring str 1 (- (string-length str) 1)))