From 7bb7d3cdd655d23c7af902e57aa6326df59933c1 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 7 Oct 2019 23:18:34 +0800 Subject: [PATCH] [html-document] schemify gnc:html-document-tree-collapse this function is technically a flattening function, converted to classic scheme form. very efficient in time and space. it is used extensively in reports which are still running well, therefore no additional testing is required. --- .../report/report-system/html-document.scm | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/gnucash/report/report-system/html-document.scm b/gnucash/report/report-system/html-document.scm index ecb045e2c3..906ab30b89 100644 --- a/gnucash/report/report-system/html-document.scm +++ b/gnucash/report/report-system/html-document.scm @@ -105,20 +105,11 @@ (apply gnc:make-html-data-style-info rest) (apply gnc:make-html-markup-style-info rest)))) -(define (gnc:html-document-tree-collapse tree) - (let ((retval '())) - (let loop ((lst tree)) - (for-each - (lambda (elt) - (cond - ((string? elt) - (set! retval (cons elt retval))) - ((not (list? elt)) - (set! retval (cons (object->string elt) retval))) - (else - (loop elt)))) - lst)) - retval)) +(define (gnc:html-document-tree-collapse . tree) + (let lp ((e tree) (accum '())) + (cond ((list? e) (fold lp accum e)) + ((string? e) (cons e accum)) + (else (cons (object->string e) accum))))) ;; first optional argument is "headers?" ;; returns the html document as a string, I think.