mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[balsheet-eg] don't use safe-cadr and safe-cdr
they are safety hacks which indicate inability to deal with lists. use lists properly.
This commit is contained in:
parent
8ffe7771f1
commit
f1ff789657
@ -46,11 +46,13 @@
|
|||||||
;; 'Safe' versions of cdr and cadr that don't crash
|
;; 'Safe' versions of cdr and cadr that don't crash
|
||||||
;; if the list is empty (is there a better way?)
|
;; if the list is empty (is there a better way?)
|
||||||
(define-public safe-cdr
|
(define-public safe-cdr
|
||||||
|
;; deprecate
|
||||||
(match-lambda
|
(match-lambda
|
||||||
((_ . x) x)
|
((_ . x) x)
|
||||||
(_ '())))
|
(_ '())))
|
||||||
|
|
||||||
(define-public safe-cadr
|
(define-public safe-cadr
|
||||||
|
;; deprecate
|
||||||
(match-lambda
|
(match-lambda
|
||||||
((_ x . y) x)
|
((_ x . y) x)
|
||||||
(_ '())))
|
(_ '())))
|
||||||
|
@ -458,13 +458,12 @@
|
|||||||
(>= (gnc-account-get-current-depth (car account-list))
|
(>= (gnc-account-get-current-depth (car account-list))
|
||||||
curr-depth))
|
curr-depth))
|
||||||
(let* ((account (car account-list))
|
(let* ((account (car account-list))
|
||||||
|
(accrest (cdr account-list))
|
||||||
|
(accnext (and (pair? accrest) (car accrest)))
|
||||||
(comm (xaccAccountGetCommodity account))
|
(comm (xaccAccountGetCommodity account))
|
||||||
(bal (xaccAccountGetBalanceAsOfDate account opt-date))
|
(bal (xaccAccountGetBalanceAsOfDate account opt-date))
|
||||||
(depth (flattened-acc-depth account))
|
(depth (flattened-acc-depth account))
|
||||||
(treedepth 1)
|
(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)))
|
(newacc (newaccrec-clean)))
|
||||||
(accrec-set-account! newacc account)
|
(accrec-set-account! newacc account)
|
||||||
(accrec-set-code! newacc (xaccAccountGetCode account))
|
(accrec-set-code! newacc (xaccAccountGetCode account))
|
||||||
@ -483,11 +482,11 @@
|
|||||||
(add-to-cc total-cc comm bal neg?)
|
(add-to-cc total-cc comm bal neg?)
|
||||||
(add-to-cc (accrec-subtotal-cc newacc) 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,
|
;; recurse to deal with deeper level accounts,
|
||||||
;; then store the resulting list
|
;; then store the resulting list
|
||||||
(let* ((result-v (process-acc-list-r
|
(let* ((result-v (process-acc-list-r accrest (1+ curr-depth) neg?))
|
||||||
(safe-cdr account-list) (1+ curr-depth) neg?))
|
|
||||||
(subtree (vector-ref result-v 0))
|
(subtree (vector-ref result-v 0))
|
||||||
(subtotal-cc (vector-ref result-v 2))
|
(subtotal-cc (vector-ref result-v 2))
|
||||||
(subtreedepth (vector-ref result-v 3))
|
(subtreedepth (vector-ref result-v 3))
|
||||||
|
Loading…
Reference in New Issue
Block a user