From c69b545aa173682e2957b1a87ab2075b35c816e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Mon, 17 Apr 2023 22:37:19 +0200 Subject: [PATCH] Allow generating table as list of strings. --- src/table.scm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/table.scm b/src/table.scm index 7148de3..376fe1d 100644 --- a/src/table.scm +++ b/src/table.scm @@ -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