Allow generating table as list of strings.

This commit is contained in:
Dominik Pantůček 2023-04-17 22:37:19 +02:00
parent 3739a8d1b0
commit c69b545aa1

View file

@ -29,6 +29,7 @@
table
(
*table-border-style*
table->list
table->string
table-tests!
)
@ -270,8 +271,8 @@
(if cb (sref 2) "")
(if tb (sref 3) "")))
;; Converts given table to a string suitable for printing.
(define (table->string tbl . args)
;; Converts given table to a list of strings suitable for printing.
(define (table->list tbl . args)
(let ((table (table-prepare tbl)))
(if (or (null? tbl)
(null? (car tbl)))
@ -315,9 +316,7 @@
3)
res)
res)))
(string-intersperse
(flatten (reverse res0))
"\n"))
(flatten (reverse res0)))
(let* ((res0
(if (or (and row-border
(> idx 0))
@ -341,6 +340,12 @@
res1
(add1 idx)))))))))
;; Converts into single string
(define (table->string . args)
(string-intersperse
(apply table->list args)
"\n"))
;; Performs module self-tests
(define (table-tests!)
(run-tests