Skip to content

Commit

Permalink
[balsheet-eg] don't use safe-cadr and safe-cdr
Browse files Browse the repository at this point in the history
they are safety hacks which indicate inability to deal with lists. use
lists properly.
  • Loading branch information
christopherlam committed May 9, 2020
1 parent 8ffe777 commit f1ff789
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions gnucash/report/eguile-utilities.scm
Expand Up @@ -46,11 +46,13 @@
;; 'Safe' versions of cdr and cadr that don't crash
;; if the list is empty (is there a better way?)
(define-public safe-cdr
;; deprecate
(match-lambda
((_ . x) x)
(_ '())))

(define-public safe-cadr
;; deprecate
(match-lambda
((_ x . y) x)
(_ '())))
Expand Down
11 changes: 5 additions & 6 deletions gnucash/report/reports/standard/balsheet-eg.scm
Expand Up @@ -458,13 +458,12 @@
(>= (gnc-account-get-current-depth (car account-list))
curr-depth))
(let* ((account (car account-list))
(accrest (cdr account-list))
(accnext (and (pair? accrest) (car accrest)))
(comm (xaccAccountGetCommodity account))
(bal (xaccAccountGetBalanceAsOfDate account opt-date))
(depth (flattened-acc-depth account))
(treedepth 1)
;; Next account only qualifies as 'deeper' if we're not flattening
(next-acc-deeper (and (not (null? (safe-cadr account-list)))
(> (flattened-acc-depth (safe-cadr account-list)) depth)))
(newacc (newaccrec-clean)))
(accrec-set-account! newacc account)
(accrec-set-code! newacc (xaccAccountGetCode account))
Expand All @@ -483,11 +482,11 @@
(add-to-cc total-cc comm bal neg?)
(add-to-cc (accrec-subtotal-cc newacc) comm bal neg?)

(if next-acc-deeper
;; Next account only qualifies as 'deeper' if we're not flattening
(if (and accnext (> (flattened-acc-depth accnext) depth))
;; recurse to deal with deeper level accounts,
;; then store the resulting list
(let* ((result-v (process-acc-list-r
(safe-cdr account-list) (1+ curr-depth) neg?))
(let* ((result-v (process-acc-list-r accrest (1+ curr-depth) neg?))
(subtree (vector-ref result-v 0))
(subtotal-cc (vector-ref result-v 2))
(subtreedepth (vector-ref result-v 3))
Expand Down

0 comments on commit f1ff789

Please sign in to comment.