gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Wed Sep 2 07:23:35 EDT 2015


Updated	 via  https://github.com/Gnucash/gnucash/commit/c9feb7df (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0ceb09ad (commit)
	from  https://github.com/Gnucash/gnucash/commit/7e07e6ce (commit)



commit c9feb7df8740b0350ab75deecfe6e1e9fcb11a01
Author: Daniel Kraft <d at domob.eu>
Date:   Sun Aug 30 18:54:04 2015 +0200

    Define build-report! function instead of loop.
    
    The existing code uses tuples to define the properties of the individual
    reports created.  Replace that by a function to build one of them which
    gets the properties passed as arguments, and use a series of calls to
    replace the old loop.  This makes the properties much more easier to
    read.

diff --git a/src/report/standard-reports/account-piecharts.scm b/src/report/standard-reports/account-piecharts.scm
index e076150..1f3d5c6 100644
--- a/src/report/standard-reports/account-piecharts.scm
+++ b/src/report/standard-reports/account-piecharts.scm
@@ -536,39 +536,57 @@ balance at a given time"))
       (gnc:report-finished)
       document)))
 
-(for-each 
- (lambda (l)
-   (let ((tip-and-rev (cddddr l)))
-     (gnc:define-report
-      'version 1
-      'name (car l)
-      'report-guid (car (reverse l))
-      'menu-path (if (caddr l)
-		     (list gnc:menuname-income-expense)
-		     (list gnc:menuname-asset-liability)) 
-      'menu-name (cadddr l) 
-      'menu-tip (car tip-and-rev)
-      'options-generator (lambda () (options-generator (cadr l)  
-						       (cadr tip-and-rev)
-						       (caddr l)))
-      'renderer (lambda (report-obj)
-		  (piechart-renderer report-obj 
-				     (car l) 
-				     (car (reverse l))
-				     (cadr l)
-				     (caddr l))))))
- (list 
-  ;; reportname, account-types, do-intervals?, 
-  ;; menu-reportname, menu-tip
-  (list reportname-income (list ACCT-TYPE-INCOME) #t menuname-income menutip-income (lambda (x) #t) "e1bd09b8a1dd49dd85760db9d82b045c")
-  (list reportname-expense (list ACCT-TYPE-EXPENSE) #t menuname-expense menutip-expense (lambda (x) #f) "9bf1892805cb4336be6320fe48ce5446")
-  (list reportname-assets
-        (list ACCT-TYPE-ASSET ACCT-TYPE-BANK ACCT-TYPE-CASH ACCT-TYPE-CHECKING
-              ACCT-TYPE-SAVINGS ACCT-TYPE-MONEYMRKT
-              ACCT-TYPE-RECEIVABLE ACCT-TYPE-STOCK ACCT-TYPE-MUTUAL
-              ACCT-TYPE-CURRENCY)
-        #f menuname-assets menutip-assets (lambda (x) #f) "5c7fd8a1fe9a4cd38884ff54214aa88a")
-  (list reportname-liabilities 
-        (list ACCT-TYPE-LIABILITY ACCT-TYPE-PAYABLE ACCT-TYPE-CREDIT
-              ACCT-TYPE-CREDITLINE)
-        #f menuname-liabilities menutip-liabilities (lambda (x) #t) "3fe6dce77da24c66bdc8f8efdea7f9ac")))
+(define (build-report!
+          name acct-types income-expense? menuname menutip
+          reverse-balance? uuid)
+  (gnc:define-report
+    'version 1
+    'name name
+    'report-guid uuid
+    'menu-path (if income-expense?
+                   (list gnc:menuname-income-expense)
+                   (list gnc:menuname-asset-liability))
+    'menu-name menuname
+    'menu-tip menutip
+    'options-generator (lambda () (options-generator acct-types
+                                                     reverse-balance?
+                                                     income-expense?))
+    'renderer (lambda (report-obj)
+                (piechart-renderer report-obj name uuid
+                                   acct-types income-expense?))))
+
+(build-report!
+  reportname-income
+  (list ACCT-TYPE-INCOME)
+  #t
+  menuname-income menutip-income
+  (lambda (x) #t)
+  "e1bd09b8a1dd49dd85760db9d82b045c")
+
+(build-report!
+  reportname-expense
+  (list ACCT-TYPE-EXPENSE)
+  #t
+  menuname-expense menutip-expense
+  (lambda (x) #f)
+  "9bf1892805cb4336be6320fe48ce5446")
+
+(build-report!
+  reportname-assets
+  (list ACCT-TYPE-ASSET ACCT-TYPE-BANK ACCT-TYPE-CASH ACCT-TYPE-CHECKING
+        ACCT-TYPE-SAVINGS ACCT-TYPE-MONEYMRKT
+        ACCT-TYPE-RECEIVABLE ACCT-TYPE-STOCK ACCT-TYPE-MUTUAL
+        ACCT-TYPE-CURRENCY)
+  #f
+  menuname-assets menutip-assets
+  (lambda (x) #f)
+  "5c7fd8a1fe9a4cd38884ff54214aa88a")
+
+(build-report!
+  reportname-liabilities
+  (list ACCT-TYPE-LIABILITY ACCT-TYPE-PAYABLE ACCT-TYPE-CREDIT
+        ACCT-TYPE-CREDITLINE)
+  #f
+  menuname-liabilities menutip-liabilities
+  (lambda (x) #t)
+  "3fe6dce77da24c66bdc8f8efdea7f9ac")

commit 0ceb09ada6a7b9d4aacc82f175a6d9767f5cb39c
Author: Daniel Kraft <d at domob.eu>
Date:   Sun Aug 30 18:03:14 2015 +0200

    Replace for-each by tail recursion.
    
    Replace the use of for-each and set! by tail-recursive calls with
    accumulator variables.  This is a more "Schematic" way to do the loops.

diff --git a/src/report/standard-reports/account-piecharts.scm b/src/report/standard-reports/account-piecharts.scm
index 74fcae5..e076150 100644
--- a/src/report/standard-reports/account-piecharts.scm
+++ b/src/report/standard-reports/account-piecharts.scm
@@ -315,13 +315,15 @@ balance at a given time"))
 
       (define (count-accounts current-depth accts)
 	(if (< current-depth tree-depth)
-	    (let ((sum 0))
-	      (for-each
-	       (lambda (a)
-		 (set! sum (+ sum (+ 1 (count-accounts (+ 1 current-depth)
-						       (gnc-account-get-children a))))))
-	       accts)
-	      sum)
+            (let iter ((sum 0)
+                       (remaining accts))
+              (if (null? remaining)
+                  sum
+                  (let* ((cur (car remaining))
+                         (tail (cdr remaining))
+                         (subaccts (count-accounts (1+ current-depth)
+                                                   (gnc-account-get-children cur))))
+                    (iter (+ sum (1+ subaccts)) tail))))
 	    (length (filter show-acct? accts))))
 
       ;; Calculates all account's balances. Returns a list of
@@ -336,23 +338,28 @@ balance at a given time"))
       ;; parent.
       (define (traverse-accounts current-depth accts)
         (if (< current-depth tree-depth)
-            (let ((res '()))
-              (for-each
-               (lambda (a)
-                 (begin
-		   (set! work-done (+ 1 work-done))
-		   (gnc:report-percent-done (* 100 (/ work-done work-to-do)))
-                   (if (show-acct? a)
-                       (set! res (cons (list (collector->double 
-                                              (profit-fn a #f)) a)
-                                       res)))
-                   (set! res (append
-                              (traverse-accounts
-                               (+ 1 current-depth)
-                               (gnc-account-get-children a))
-                              res))))
-               accts)
-              res)
+            (let iter ((res '())
+                       (remaining accts))
+              (if (null? remaining)
+                  res
+                  (begin
+		    (set! work-done (+ 1 work-done))
+		    (gnc:report-percent-done (* 100 (/ work-done work-to-do)))
+                    (let* ((cur (car remaining))
+                           (tail (cdr remaining))
+                           (subaccts (traverse-accounts
+                                       (1+ current-depth)
+                                       (gnc-account-get-children cur))))
+                      (iter
+                        (append
+                          subaccts
+                          (if (show-acct? cur)
+                              (cons
+                                (list (collector->double (profit-fn cur #f))
+                                      cur)
+                                res)
+                              res))
+                        tail)))))
             (map
              (lambda (a)
 	       (set! work-done (+ 1 work-done))



Summary of changes:
 src/report/standard-reports/account-piecharts.scm | 145 +++++++++++++---------
 1 file changed, 85 insertions(+), 60 deletions(-)



More information about the gnucash-changes mailing list