rs: Add read-ctx and illustrate it in example.org.

This commit is contained in:
Sergiu Ivanov 2020-03-02 23:11:26 +01:00
parent 171147ad5e
commit c0d36a34a7
2 changed files with 20 additions and 1 deletions

View file

@ -519,6 +519,22 @@ tab
- a - a
- b - 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 :noexport:
# Local Variables: # Local Variables:

5
rs.rkt
View file

@ -31,7 +31,7 @@
;; Contracts ;; Contracts
(contract-out [reaction-system/c contract?]) (contract-out [reaction-system/c contract?])
;; Syntax ;; Syntax
unorg-rs org-rs) unorg-rs org-rs read-ctx)
;;; ================= ;;; =================
;;; Basic definitions ;;; Basic definitions
@ -107,6 +107,9 @@
(define (read-context-sequence str) (define (read-context-sequence str)
(map (compose list->set read-symbol-list) (flatten (read-org-sexp 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. ;;; Removes the first and the last symbol of a given string.
(define (drop-first-last str) (define (drop-first-last str)
(substring str 1 (- (string-length str) 1))) (substring str 1 (- (string-length str) 1)))