Email list hosting service & mailing list manager


Re: Folds and reductions John David Stone 11 Jan 1999 17:59 UTC

        Now that I think about it, there are a couple of small improvements
to be made in the code I wrote at
http://srfi.schemers.org/srfi-1/mail-archive/msg00021.html:

        In PAIR-FOLDL, it's pointless to cons ANS onto LISTS in the call
(APPLY F (CONS ANS LISTS)), since if consing is needed APPLY will do it
internally:

(define (pair-foldl f zero lis1 . lists)
  (if (pair? lists)
      (let lp ((lists (cons lis1 lists)) (ans zero))
        (if (%all-pairs? lists)
            (let ((tails (%cdrs lists)))
              (lp tails (apply f ans lists)))
            ans))
      (let lp ((lis lis1) (ans zero))
        (if (pair? lis)
            (let ((tail (cdr lis)))
              (lp tail (f ans lis)))
            ans))))

        Given my remarks in (1) and (2) of the earlier message, LIDENTITY
would be a better identifier for the third parameter of REDUCEL:

(define (reducel f lidentity lis)
  (if (pair? lis)
      (foldl f (car lis) (cdr lis))
      lidentity))

--
======  John David Stone - Lecturer in Computer Science and Philosophy  =====
==============  Manager of the Mathematics Local-Area Network  ==============
==============  Grinnell College - Grinnell, Iowa 50112 - USA  ==============
==========  xxxxxx@math.grin.edu - http://www.math.grin.edu/~stone/  =========