From 835b89bbb8af4c9b30fe6da69e774fe0b99fa715 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Tue, 13 Oct 2020 23:25:21 +0200 Subject: [PATCH] networks: Add read-org-sbfs/state. --- networks.rkt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/networks.rkt b/networks.rkt index f9ff6dc..53fbe9c 100644 --- a/networks.rkt +++ b/networks.rkt @@ -92,6 +92,7 @@ (#:headers boolean?) (listof sbf/state?))] [read-org-tbfs/state (->* (string?) (#:headers boolean?) (listof tbf/state?))] + [read-org-sbfs/state (->* (string?) (#:headers boolean?) (listof sbf/state?))] [print-org-tbfs/state (->* ((non-empty-listof tbf/state?)) (#:headers boolean?) (listof (listof (or/c number? symbol?))))] [tbf/state-tabulate* (->* ((non-empty-listof tbf/state?)) (#:headers boolean?) @@ -1110,6 +1111,28 @@ (tbf/state '#hash((x0 . 1) (x1 . 2)) 3) (tbf/state '#hash((x0 . 1) (x1 . 1)) 2))))) +;;; Like read-org-tbfs/state, but reads a list of SBFs. Therefore, +;;; the lists of numbers in the sexp are taken to be the weights of +;;; the SBFs. +;;; +;;; If headers is #t, the names of the variables to appear as the +;;; inputs of the TBF are taken from the first list. If headers is +;;; #f, the names of the variables are generated as xi, where i is the +;;; index of the variable. +(define (read-org-sbfs/state str #:headers [headers #t]) + (lists->sbfs/state (read-org-sexp str) #:headers headers)) + +(module+ test + (test-case "read-org-sbfs/state" + (check-equal? (read-org-sbfs/state "((a b) (-1 2) (1 1))") + (list + (tbf/state '#hash((a . -1) (b . 2)) 0) + (tbf/state '#hash((a . 1) (b . 1)) 0))) + (check-equal? (read-org-sbfs/state "((-1 2) (1 1))" #:headers #f) + (list + (tbf/state '#hash((x0 . -1) (x1 . 2)) 0) + (tbf/state '#hash((x0 . 1) (x1 . 1)) 0))))) + ;;; Given a list of tbf/state, produces a sexp that Org-mode can ;;; interpret as a table. ;;;