array-fold, array-fold-right, and array-reduce
Bradley Lucier 19 Aug 2021 19:10 UTC
Joe Marshall discusses fold-left and fold-right here:
http://funcall.blogspot.com/2021/08/fold-right.html
His post has raised questions in my mind about whether SRFI 179 defines
array-fold, array-fold-right, and array-reduce in The Right Way (TM). I
added a comment that notes:
heine:~/programs/gambit/gambit> gsi
Gambit v4.9.3-1503-gd1a6c6bf
> (import (srfi 179))
> (define a (make-array (make-interval '#(2 2))
(lambda (i j)
(string->symbol (string-append "a_"
(number->string i) (number->string j))))))
> (array-fold (lambda (l r) `(f ,l ,r)) 'init a)
(f a_11 (f a_10 (f a_01 (f a_00 init))))
> (array-fold-right (lambda (l r) `(f ,l ,r)) 'init a)
(f a_00 (f a_01 (f a_10 (f a_11 init))))
> (array-reduce (lambda (l r) `(f ,l ,r)) a)
(f (f (f a_00 a_01) a_10) a_11)
These functions work the way they're documented, so I don't think any
errata need to be applied to SRFI 179, but I'm wondering if this is
another small thing that should be changed in a follow-up SRFI.
Brad