[Gnucash-changes] r13476 - gnucash/trunk/src/engine - Use for-each, lambda expressions for iterating over split lists.

Chris Shoemaker chris at cvs.gnucash.org
Sat Mar 4 13:12:35 EST 2006


Author: chris
Date: 2006-03-04 13:12:34 -0500 (Sat, 04 Mar 2006)
New Revision: 13476
Trac: http://svn.gnucash.org/trac/changeset/13476

Modified:
   gnucash/trunk/src/engine/engine-interface.scm
Log:
   Use for-each, lambda expressions for iterating over split lists.
   In contrast to the previous looping construct, this will work even if 
   the split operations don't have side-effects on the split lists.


Modified: gnucash/trunk/src/engine/engine-interface.scm
===================================================================
--- gnucash/trunk/src/engine/engine-interface.scm	2006-03-04 16:28:52 UTC (rev 13475)
+++ gnucash/trunk/src/engine/engine-interface.scm	2006-03-04 18:12:34 UTC (rev 13476)
@@ -263,28 +263,25 @@
                            trans date-posted)))
 
         ;; strip off the old splits
-        (let loop ((split (gnc:transaction-get-split trans 0)))
-          (if split
-              (begin
-                (gnc:split-destroy split)
-                (loop (gnc:transaction-get-split trans 0)))))
+        (for-each (lambda (split)
+                    (gnc:split-destroy split)) 
+                  (gnc:transaction-get-splits trans))
 
         ;; and put on the new ones! Please note they go in the *same*
         ;; order as in the original transaction. This is important.
-        (let loop ((split-scms (gnc:transaction-scm-get-split-scms trans-scm)))
-          (if (pair? split-scms)
-              (let* ((new-split (gnc:split-create book))
-                     (split-scm (car split-scms))
-                     (old-guid  (gnc:split-scm-get-account-guid split-scm))
-                     (new-guid  (assoc-ref guid-mapping old-guid)))
-                (if (not new-guid)
-                    (set! new-guid old-guid))
-                (gnc:split-scm-set-account-guid split-scm new-guid)
-                (gnc:split-scm-onto-split split-scm new-split book)
-                (gnc:split-scm-set-account-guid split-scm old-guid)
-                (gnc:transaction-append-split trans new-split)
-                (loop (cdr split-scms)))))
-
+        (for-each 
+         (lambda (split-scm) 
+           (let* ((new-split (gnc:split-create book))
+                  (old-guid  (gnc:split-scm-get-account-guid split-scm))
+                  (new-guid  (assoc-ref guid-mapping old-guid)))
+             (if (not new-guid)
+                 (set! new-guid old-guid))
+             (gnc:split-scm-set-account-guid split-scm new-guid)
+             (gnc:split-scm-onto-split split-scm new-split book)
+             (gnc:split-scm-set-account-guid split-scm old-guid)
+             (gnc:transaction-append-split trans new-split)))
+         (gnc:transaction-scm-get-split-scms trans-scm))
+        
         ;; close the transaction
         (if commit?
             (gnc:transaction-commit-edit trans)))))



More information about the gnucash-changes mailing list