Skip to content

Commit

Permalink
[report-utilities] rewrite list-set-safe! using named let
Browse files Browse the repository at this point in the history
This avoids some set! calls
  • Loading branch information
christopherlam committed Sep 9, 2018
1 parent 7a63fab commit 4f90663
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions gnucash/report/report-system/report-utilities.scm
Expand Up @@ -24,17 +24,15 @@
(list-ref list elt)))

(define (list-set-safe! l elt val)
(if (and (list? l) (> (length l) elt))
(unless (list? l)
(set! l '()))
(if (> (length l) elt)
(list-set! l elt val)
(let ((filler (list val)))
(if (not (list? l))
(set! l '()))
(let loop ((i (length l)))
(if (< i elt)
(begin
(set! filler (cons #f filler))
(loop (+ 1 i)))))
(set! l (append! l filler))))
(let loop ((filler (list val))
(i (length l)))
(if (< i elt)
(loop (cons #f filler) (1+ i))
(set! l (append! l filler)))))
l)

;; pair is a list of one gnc:commodity and one gnc:numeric
Expand Down

0 comments on commit 4f90663

Please sign in to comment.