mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[eguile reports] eradicate pythonic for loops, use for-each instead
this syntax is pythonic rather than lispy, is not recognized by code highlighters, and is not necessary to seasoned schemers.
This commit is contained in:
parent
17727a7b77
commit
66c7a0744c
@ -99,8 +99,11 @@
|
|||||||
;; If no file is found, returns just 'fname' for use in error messages.
|
;; If no file is found, returns just 'fname' for use in error messages.
|
||||||
(find-internal "templates" fname))
|
(find-internal "templates" fname))
|
||||||
|
|
||||||
; Define syntax for more readable for loops (the built-in for-each requires an
|
;; Define syntax for more readable for loops (the built-in for-each
|
||||||
; explicit lambda and has the list expression all the way at the end).
|
;; requires an explicit lambda and has the list expression all the way
|
||||||
|
;; at the end). Note: deprecated in 4.x, removal in 5.x. this syntax
|
||||||
|
;; is pythonic rather than lispy, is not recognized by code
|
||||||
|
;; highlighters, and is not necessary to seasoned schemers.
|
||||||
(export for)
|
(export for)
|
||||||
(define-syntax for
|
(define-syntax for
|
||||||
(syntax-rules (for in do)
|
(syntax-rules (for in do)
|
||||||
@ -110,8 +113,12 @@
|
|||||||
;; Note that this template must be defined before the
|
;; Note that this template must be defined before the
|
||||||
;; next one, since the template are evaluated in-order.
|
;; next one, since the template are evaluated in-order.
|
||||||
((for (<var> ...) in (<list> ...) do <expr> ...)
|
((for (<var> ...) in (<list> ...) do <expr> ...)
|
||||||
(for-each (lambda (<var> ...) <expr> ...) <list> ...))
|
(begin
|
||||||
|
(issue-deprecation-warning "for loops are deprecated. use for-each instead.")
|
||||||
|
(for-each (lambda (<var> ...) <expr> ...) <list> ...)))
|
||||||
|
|
||||||
;; Single variable and list. e.g.: (for a in lst do (display a))
|
;; Single variable and list. e.g.: (for a in lst do (display a))
|
||||||
((for <var> in <list> do <expr> ...)
|
((for <var> in <list> do <expr> ...)
|
||||||
(for-each (lambda (<var>) <expr> ...) <list>))))
|
(begin
|
||||||
|
(issue-deprecation-warning "for loops are deprecated. use for-each instead.")
|
||||||
|
(for-each (lambda (<var>) <expr> ...) <list>)))))
|
||||||
|
@ -46,12 +46,12 @@
|
|||||||
(define debugging? #f)
|
(define debugging? #f)
|
||||||
|
|
||||||
(define (debug . args)
|
(define (debug . args)
|
||||||
(if debugging?
|
(when debugging?
|
||||||
(for arg in args do
|
(for-each
|
||||||
(if (string? arg)
|
(lambda (arg)
|
||||||
(display (string-append arg " "))
|
(display (if (string? arg) arg (dump arg)))
|
||||||
(display (string-append (dump arg) " "))))
|
(display " "))
|
||||||
))
|
args)))
|
||||||
|
|
||||||
(define (hrule cols) ; in fact just puts in an empty row for spacing
|
(define (hrule cols) ; in fact just puts in an empty row for spacing
|
||||||
(display "<tr valign=\"center\"><td colspan=\"")
|
(display "<tr valign=\"center\"><td colspan=\"")
|
||||||
@ -102,10 +102,12 @@
|
|||||||
(display " sublist: ") (if (accrec-sublist accrec)
|
(display " sublist: ") (if (accrec-sublist accrec)
|
||||||
(begin
|
(begin
|
||||||
(display "\n<ul>")
|
(display "\n<ul>")
|
||||||
(for sub-accrec in (accrec-sublist accrec) do
|
(for-each
|
||||||
|
(lambda (sub-accrec)
|
||||||
(display "\n<li>")
|
(display "\n<li>")
|
||||||
(accrec-printer sub-accrec port)
|
(accrec-printer sub-accrec port)
|
||||||
(display "</li>"))
|
(display "</li>"))
|
||||||
|
(accrec-sublist accrec))
|
||||||
(display "</ul>"))
|
(display "</ul>"))
|
||||||
(display "#f")))
|
(display "#f")))
|
||||||
(define accrectype (make-record-type "accrecc"
|
(define accrectype (make-record-type "accrecc"
|
||||||
@ -122,6 +124,7 @@
|
|||||||
subtotal-cc ; of sublist plus this a/c
|
subtotal-cc ; of sublist plus this a/c
|
||||||
sublist)
|
sublist)
|
||||||
accrec-printer))
|
accrec-printer))
|
||||||
|
|
||||||
(define newaccrec-full (record-constructor accrectype)) ; requires all the fields
|
(define newaccrec-full (record-constructor accrectype)) ; requires all the fields
|
||||||
(define (newaccrec-clean)
|
(define (newaccrec-clean)
|
||||||
;; Create a new accrec with 'clean' empty values, e.g. strings are "", not #f
|
;; Create a new accrec with 'clean' empty values, e.g. strings are "", not #f
|
||||||
|
@ -76,43 +76,36 @@
|
|||||||
onedepth1)
|
onedepth1)
|
||||||
;; Recursively display the accounts table from the given tree
|
;; Recursively display the accounts table from the given tree
|
||||||
;; (as returned by process-acc-list)
|
;; (as returned by process-acc-list)
|
||||||
(for accrec in tree do
|
(for-each
|
||||||
(let ((rshift2 0) ; adjust the amount column by this much
|
(lambda (accrec)
|
||||||
(showamt? #t)) ; whether to show the amount (e.g. not if zero)
|
|
||||||
(if (and (accrec-sublist accrec)
|
|
||||||
; (> (accrec-depth accrec) 0))
|
|
||||||
)
|
|
||||||
; has sub-accounts: shift left to put balance in same column as sub-accounts
|
|
||||||
(set! rshift2 -1))
|
|
||||||
; Don't show zero amount for a placeholder -- the value to
|
|
||||||
; test for zero depends on whether or not this is a 'summary' value
|
|
||||||
; (i.e. a total of sub-accounts that are not shown separately)
|
|
||||||
(if (and (accrec-placeholder? accrec)
|
|
||||||
(if (accrec-summary? accrec)
|
|
||||||
(not (accrec-non-zero? accrec))
|
|
||||||
(gnc-numeric-zero-p (accrec-balance-num accrec))))
|
|
||||||
(set! showamt? #f))
|
|
||||||
(display-acc-row
|
(display-acc-row
|
||||||
maxdepth
|
maxdepth
|
||||||
(accrec-depth accrec)
|
(accrec-depth accrec)
|
||||||
(+ rshift rshift2)
|
;; has sub-accounts: shift left to put balance in same column
|
||||||
|
;; as sub-accounts
|
||||||
|
(+ rshift (if (accrec-sublist accrec) -1 0))
|
||||||
(accrec-namelink accrec)
|
(accrec-namelink accrec)
|
||||||
(if showamt?
|
;; Don't show zero amount for a placeholder -- the value to
|
||||||
|
;; test for zero depends on whether or not this is a 'summary'
|
||||||
|
;; value (i.e. a total of sub-accounts that are not shown
|
||||||
|
;; separately)
|
||||||
|
(cond
|
||||||
|
((and (accrec-placeholder? accrec)
|
||||||
(if (accrec-summary? accrec)
|
(if (accrec-summary? accrec)
|
||||||
(format-comm-coll (accrec-subtotal-cc accrec))
|
(not (accrec-non-zero? accrec))
|
||||||
(format-monetary (accrec-balance-mny accrec)))
|
(zero? (accrec-balance-num accrec))))
|
||||||
" "
|
" ")
|
||||||
)
|
((accrec-summary? accrec) (format-comm-coll (accrec-subtotal-cc accrec)))
|
||||||
|
(else (format-monetary (accrec-balance-mny accrec))))
|
||||||
(< (accrec-depth accrec) 1); total?
|
(< (accrec-depth accrec) 1); total?
|
||||||
#f) ; leftoverrule?
|
#f) ; leftoverrule?
|
||||||
(if (accrec-sublist accrec)
|
(when (accrec-sublist accrec)
|
||||||
(begin
|
;; recurse to deeper accounts...
|
||||||
; recurse to deeper accounts...
|
(display-accounts-table-r
|
||||||
(display-accounts-table-r (accrec-sublist accrec) neg? maxdepth rshift onedepth1)
|
(accrec-sublist accrec) neg? maxdepth rshift onedepth1)
|
||||||
; ...and then display the total
|
;; ...and then display the total
|
||||||
; unless there is only one depth-1 account
|
;; unless there is only one depth-1 account
|
||||||
(if (not (and onedepth1
|
(unless (and onedepth1 (= 1 (accrec-depth accrec)))
|
||||||
(= 1 (accrec-depth accrec))))
|
|
||||||
(display-acc-row
|
(display-acc-row
|
||||||
maxdepth
|
maxdepth
|
||||||
(accrec-depth accrec)
|
(accrec-depth accrec)
|
||||||
@ -120,8 +113,9 @@
|
|||||||
(string-append (_ "Total") " " (accrec-namelink accrec))
|
(string-append (_ "Total") " " (accrec-namelink accrec))
|
||||||
(format-comm-coll-total (accrec-subtotal-cc accrec))
|
(format-comm-coll-total (accrec-subtotal-cc accrec))
|
||||||
(<= (accrec-depth accrec) 1) ; total?
|
(<= (accrec-depth accrec) 1) ; total?
|
||||||
(> (accrec-depth accrec) 0))))))) ; leftoverrule?
|
(> (accrec-depth accrec) 0))))) ; leftoverrule?
|
||||||
)
|
|
||||||
|
tree))
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- The HTML starts here... -->
|
<!-- The HTML starts here... -->
|
||||||
|
Loading…
Reference in New Issue
Block a user