array-fold, array-fold-right, and array-reduce Bradley Lucier (19 Aug 2021 19:10 UTC)
Re: array-fold, array-fold-right, and array-reduce Alex Shinn (20 Aug 2021 00:27 UTC)
Re: array-fold, array-fold-right, and array-reduce Bradley Lucier (20 Aug 2021 00:58 UTC)
Re: array-fold, array-fold-right, and array-reduce Alex Shinn (20 Aug 2021 03:07 UTC)
Re: array-fold, array-fold-right, and array-reduce John Cowan (20 Aug 2021 20:31 UTC)
Re: array-fold, array-fold-right, and array-reduce Bradley Lucier (23 Aug 2021 00:51 UTC)

Re: array-fold, array-fold-right, and array-reduce Bradley Lucier 23 Aug 2021 00:51 UTC

I began this discussion after reading Joe Marshall's blog post on
fold-right.

After looking over fold-{left|right} in Haskell, OCaml, and SRFI 1, I
believe that the definition of fold (fold-left) in SRFI 1 does not
conform to the general understanding of this function.

SRFI 179 followed SRFI 1's definition of fold to define array-fold.

And SRFI 179 seems to have screwed up the definition of array-reduce.

In any follow-up SRFI, I think I'd do something like

(array-foldl (lambda (accumulate next-element) ...) initial array)

(f (f (f ... (f (f init value_0) value_1)...) value_n-1) value_n)

(array-foldr (lambda (next-element accumulate) ...) array final)

(f value_0 (f value_1 (... (f value_n-1 (f value_n final)))))

(array-reduce (lambda (current-value next-element) ...) array)

Assumes that current-value and next-element have the same "type",
whatever that means.

The definition of array-reduce is made a bit easier because the array
argument always has elements.

Brad