[commodity-utilities] compact code, use (ice-9 match)

This commit is contained in:
Christopher Lam
2020-02-05 15:35:18 +08:00
parent ad094f4345
commit c94b433187

View File

@@ -618,10 +618,9 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
;; total balances from get-exchange-totals are divided by each
;; other.
(map
(lambda (e)
(list (car e)
(abs (/ ((cdadr e) 'total #f)
((caadr e) 'total #f)))))
(match-lambda
((comm (domestic . foreign))
(list comm (abs (/ (foreign 'total #f) (domestic 'total #f))))))
(gnc:get-exchange-totals report-commodity end-date)))
(define (gnc:make-exchange-cost-alist report-commodity end-date)
@@ -629,12 +628,10 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
;; total balances from get-exchange-totals are divided by each
;; other.
(map
(lambda (e)
(list (car e)
(if (zero? ((caadr e) 'total #f))
0
(abs (/ ((cdadr e) 'total #f)
((caadr e) 'total #f))))))
(match-lambda
((comm (domestic . foreign))
(let ((denom (domestic 'total #f)))
(list comm (if (zero? denom) 0 (abs (/ (foreign 'total #f) denom)))))))
(gnc:get-exchange-cost-totals report-commodity end-date)))
@@ -973,7 +970,7 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
(define (gnc:uniform-commodity? amt report-commodity)
;; function to see if the commodity-collector amt
;; contains any foreign commodities
(let ((list-of-commodities (amt 'format (lambda (comm amt) comm) #f)))
(or (null? list-of-commodities)
(and (null? (cdr list-of-commodities))
(gnc-commodity-equiv report-commodity (car list-of-commodities))))))
(match (amt 'format (lambda (comm amt) comm) #f)
(() #t)
((comm) (gnc-commodity-equiv report-commodity comm))
(_ #f)))