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

        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

(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)))
      (let lp ((lis lis1) (ans zero))
        (if (pair? lis)
            (let ((tail (cdr lis)))
              (lp tail (f ans lis)))

        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))

======  John David Stone - Lecturer in Computer Science and Philosophy  =====
==============  Manager of the Mathematics Local-Area Network  ==============
==============  Grinnell College - Grinnell, Iowa 50112 - USA  ==============
========== -  =========