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

Loading…
Cancel
Save