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

pull/644/head
Christopher Lam 6 years ago
parent c94b433187
commit bb986e474c

@ -23,6 +23,7 @@
;; 02111-1307 USA
(define-module (gnucash report eguile-utilities))
(use-modules (ice-9 match))
; using all of these seems like overkill --
; not sure which are really required
@ -35,13 +36,10 @@
(define-public (fmtnumber n)
;; Format a number (integer or real) into something printable
(number->string (if (integer? n)
(inexact->exact n)
n)))
(number->string (if (integer? n) (inexact->exact n) n)))
(define-public (fmtnumeric n)
;; Format gnc-numeric n with as many decimal places as required
(fmtnumber (gnc-numeric-to-double n)))
;; Format gnc-numeric n with as many decimal places as required
(define-public fmtnumeric fmtnumber)
(define-public (gnc-monetary-neg? monetary)
; return true if the monetary value is negative
@ -49,14 +47,15 @@
;; 'Safe' versions of cdr and cadr that don't crash
;; if the list is empty (is there a better way?)
(define-public (safe-cdr l)
(if (null? l) '()
(cdr l)))
(define-public (safe-cadr l)
(cond
((null? l) '())
((null? (cdr l)) '())
(else (cadr l))))
(define-public safe-cdr
(match-lambda
((_ . x) x)
(_ '())))
(define-public safe-cadr
(match-lambda
((_ x . _) x)
(_ '())))
(define-public (find-file fname)
;; Find the file 'fname', and return its full path.

Loading…
Cancel
Save