From 67751665b3011b2049d0aa6bf2b8a2556cec334b Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 23 Aug 2019 18:55:55 +0800 Subject: [PATCH] [taxtxf(-de_DE)] compact functions, use srfi-2 srfi-2 and-let* allows concise code and returns #f if any intermediate var is #f. --- libgnucash/tax/us/txf-de_DE.scm | 79 +++++++++++---------------------- libgnucash/tax/us/txf.scm | 74 +++++++++++------------------- 2 files changed, 53 insertions(+), 100 deletions(-) diff --git a/libgnucash/tax/us/txf-de_DE.scm b/libgnucash/tax/us/txf-de_DE.scm index c3df5342b4..c93cdc3f68 100644 --- a/libgnucash/tax/us/txf-de_DE.scm +++ b/libgnucash/tax/us/txf-de_DE.scm @@ -46,6 +46,7 @@ (use-modules (gnucash app-utils)) +(use-modules (srfi srfi-2)) (define txf-tax-entity-types (list @@ -53,11 +54,8 @@ (cons 'Other #("None" "Keine Steuerberichtsoptionen vorhanden")))) (define (gnc:tax-type-txf-get-code-info tax-entity-types type-code index) - (if (assv type-code tax-entity-types) - (let ((tax-entity-type (assv type-code tax-entity-types))) - (and tax-entity-type - (vector-ref (cdr tax-entity-type) index))) - #f)) + (and-let* ((tax-entity-type (assv-ref tax-entity-types type-code))) + (vector-ref tax-entity-type index))) (define (gnc:txf-get-tax-entity-type type-code) (gnc:tax-type-txf-get-code-info txf-tax-entity-types type-code 0)) @@ -81,64 +79,41 @@ (define (gnc:txf-get-category-key categories code tax-entity-type) (gnc:txf-get-code-info categories code 5 tax-entity-type)) (define (gnc:txf-get-line-data categories code tax-entity-type) - (if (assv (string->symbol tax-entity-type) categories) - (let* ((tax-entity-codes (cdr (assv (string->symbol tax-entity-type) - categories))) - (category (if (assv code tax-entity-codes) - (assv code tax-entity-codes) - #f))) - (if (or (not category) (< (vector-length (cdr category)) 7)) - #f - (gnc:txf-get-code-info categories code 6 tax-entity-type))) - #f)) + (and-let* ((sym (string->symbol tax-entity-type)) + (tax-entity-codes (assv-ref categories sym)) + (category (assv-ref tax-entity-codes code)) + ((>= (vector-length category) 7))) + (gnc:txf-get-code-info categories code 6 tax-entity-type))) (define (gnc:txf-get-last-year categories code tax-entity-type) - (if (assv (string->symbol tax-entity-type) categories) - (let* ((tax-entity-codes (cdr (assv (string->symbol tax-entity-type) - categories))) - (category (if (assv code tax-entity-codes) - (assv code tax-entity-codes) - #f))) - (if (or (not category) (< (vector-length (cdr category)) 8)) - #f - (gnc:txf-get-code-info categories code 7 tax-entity-type))) - #f)) + (and-let* ((sym (string->symbol tax-entity-type)) + (tax-entity-codes (assv-ref categories sym)) + (category (assv-ref tax-entity-codes code)) + ((>= (vector-length category) 8))) + (gnc:txf-get-code-info categories code 7 tax-entity-type))) (define (gnc:txf-get-help categories code) - (let ((pair (assv code txf-help-strings))) - (if pair - (cdr pair) - "Keine Hilfe verfügbar, da nur Gruppenüberschrift. + (or (assv-ref txf-help-strings code) + "Keine Hilfe verfügbar, da nur Gruppenüberschrift. Diese Kategorie ohne Nummer ==>> N I C H T V E R W E N D E N ! USt-Kategorien 2011 für GnuCash Vers. 2.4.0 entwickelt und erstellt von: FJSW -Fehlermeldungen + Dankschreiben an: stoll@bomhardt.de"))) +Fehlermeldungen + Dankschreiben an: stoll@bomhardt.de")) (define (gnc:txf-get-codes categories tax-entity-type) - (if (assv (string->symbol tax-entity-type) categories) - (let* ((tax-entity-code-list-pair (assv (if (eqv? tax-entity-type "") - 'Ind - (string->symbol tax-entity-type)) - categories)) - (tax-entity-codes (if tax-entity-code-list-pair - (cdr tax-entity-code-list-pair) - '()))) - (map car tax-entity-codes)) - #f)) + (and-let* ((sym (if (string-null? tax-entity-type) + 'Ind + (string->symbol tax-entity-type))) + (tax-entity-codes (assv-ref categories sym))) + (map car tax-entity-codes))) ;;;; Private (define (gnc:txf-get-code-info categories code index tax-entity-type) - (let* ((tax-entity-code-list-pair (assv (if (eqv? tax-entity-type "") - 'Ind - (string->symbol tax-entity-type)) - categories)) - (tax-entity-codes (if tax-entity-code-list-pair - (cdr tax-entity-code-list-pair) - '())) - (category (assv code tax-entity-codes))) - (if category - (and category - (vector-ref (cdr category) index)) - #f))) + (and-let* ((sym (if (string-null? tax-entity-type) + 'Ind + (string->symbol tax-entity-type))) + (tax-entity-codes (assv-ref categories sym)) + (category (assv-ref tax-entity-codes code))) + (vector-ref category index))) (define txf-help-categories (list diff --git a/libgnucash/tax/us/txf.scm b/libgnucash/tax/us/txf.scm index ffdb6f78db..ef551bea3f 100644 --- a/libgnucash/tax/us/txf.scm +++ b/libgnucash/tax/us/txf.scm @@ -41,6 +41,7 @@ (use-modules (gnucash app-utils)) +(use-modules (srfi srfi-2)) (define txf-tax-entity-types (list @@ -51,11 +52,8 @@ (cons 'Other #("None" "No Income Tax Options Provided")))) (define (gnc:tax-type-txf-get-code-info tax-entity-types type-code index) - (if (assv type-code tax-entity-types) - (let ((tax-entity-type (assv type-code tax-entity-types))) - (and tax-entity-type - (vector-ref (cdr tax-entity-type) index))) - #f)) + (and-let* ((tax-entity-type (assv-ref tax-entity-types type-code))) + (vector-ref tax-entity-type index))) (define (gnc:txf-get-tax-entity-type type-code) (gnc:tax-type-txf-get-code-info txf-tax-entity-types type-code 0)) @@ -78,57 +76,37 @@ (gnc:txf-get-code-info categories code 4 tax-entity-type)) (define (gnc:txf-get-category-key categories code tax-entity-type) (gnc:txf-get-code-info categories code 5 tax-entity-type)) + (define (gnc:txf-get-line-data categories code tax-entity-type) - (if (assv (string->symbol tax-entity-type) categories) - (let* ((tax-entity-codes (cdr (assv (string->symbol tax-entity-type) - categories))) - (category (if (assv code tax-entity-codes) - (assv code tax-entity-codes) - #f))) - (if (or (not category) (< (vector-length (cdr category)) 7)) - #f - (gnc:txf-get-code-info categories code 6 tax-entity-type))) - #f)) + (and-let* ((sym (string->symbol tax-entity-type)) + (tax-entity-codes (assv-ref categories sym)) + (category (assv-ref tax-entity-codes code)) + ((>= (vector-length category) 7))) + (gnc:txf-get-code-info categories code 6 tax-entity-type))) + (define (gnc:txf-get-last-year categories code tax-entity-type) - (if (assv (string->symbol tax-entity-type) categories) - (let* ((tax-entity-codes (cdr (assv (string->symbol tax-entity-type) - categories))) - (category (if (assv code tax-entity-codes) - (assv code tax-entity-codes) - #f))) - (if (or (not category) (< (vector-length (cdr category)) 8)) - #f - (gnc:txf-get-code-info categories code 7 tax-entity-type))) - #f)) + (and-let* ((sym (string->symbol tax-entity-type)) + (tax-entity-codes (assv-ref categories sym)) + (category (assv-ref tax-entity-codes code)) + ((>= (vector-length category) 8))) + (gnc:txf-get-code-info categories code 7 tax-entity-type))) (define (gnc:txf-get-help categories code) - (let ((pair (assv code txf-help-strings))) - (if pair - (cdr pair) - (_ "No help available.") ))) + (or (assv-ref txf-help-strings code) + (_ "No help available."))) (define (gnc:txf-get-codes categories tax-entity-type) - (if (assv (string->symbol tax-entity-type) categories) - (let ((tax-entity-codes (cdr (assv (string->symbol tax-entity-type) - categories)))) - (map car tax-entity-codes)) - #f)) + (and-let* ((sym (string->symbol tax-entity-type)) + (tax-entity-codes (assv-ref categories sym))) + (map car tax-entity-codes))) (define (gnc:txf-get-code-info categories code index tax-entity-type) - (if (or (assv (string->symbol tax-entity-type) categories) - (eqv? tax-entity-type "")) - (let* ((tax-entity-codes (cdr (assv (if (eqv? tax-entity-type "") - 'F1040 - (string->symbol tax-entity-type)) - categories))) - (category (if (assv code tax-entity-codes) - (assv code tax-entity-codes) - #f))) - (if category - (and category - (vector-ref (cdr category) index)) - #f)) - #f)) + (and-let* ((sym (if (string-null? tax-entity-type) + 'F1040 + (string->symbol tax-entity-type))) + (tax-entity-codes (assv-ref categories sym)) + (category (assv-ref tax-entity-codes code))) + (vector-ref category index))) (define txf-help-categories (list