Left folds Bradley Lucier (17 Sep 2022 22:18 UTC)
Re: Left folds Marc Nieper-Wißkirchen (18 Sep 2022 08:44 UTC)
(missing)
(missing)
Re: Left folds Bradley Lucier (20 Sep 2022 14:15 UTC)
Re: Left folds Marc Nieper-Wißkirchen (20 Sep 2022 14:25 UTC)
Re: Left folds Marc Nieper-Wißkirchen (22 Sep 2022 20:52 UTC)
Re: Left folds Lucier, Bradley J (22 Sep 2022 21:14 UTC)
Re: Left folds Marc Nieper-Wißkirchen (23 Sep 2022 09:25 UTC)
Re: Left folds John Cowan (23 Sep 2022 17:22 UTC)
Re: Left folds Marc Nieper-Wißkirchen (23 Sep 2022 17:30 UTC)
Re: Left folds Bradley Lucier (23 Sep 2022 18:39 UTC)
Re: Left folds Bradley Lucier (24 Sep 2022 00:12 UTC)
Re: Left folds Arthur A. Gleckler (24 Sep 2022 00:24 UTC)
Fwd: Left folds Marc Nieper-Wißkirchen (20 Sep 2022 14:17 UTC)
Re: Left folds John Cowan (18 Sep 2022 10:41 UTC)
Re: Left folds Marc Nieper-Wißkirchen (18 Sep 2022 13:29 UTC)
Re: Left folds Bradley Lucier (20 Sep 2022 00:32 UTC)

Re: Left folds Lucier, Bradley J 22 Sep 2022 21:14 UTC

> On Sep 22, 2022, at 4:52 PM, Marc Nieper-Wißkirchen <xxxxxx@gmail.com> wrote:
> Am Di., 20. Sept. 2022 um 16:25 Uhr schrieb Marc Nieper-Wißkirchen <xxxxxx@gmail.com>:
> Am Di., 20. Sept. 2022 um 16:15 Uhr schrieb Bradley Lucier <xxxxxx@math.purdue.edu>:
> On 9/20/22 2:02 AM, Marc Nieper-Wißkirchen wrote:
> > Is there a reason why you cite Haskell's fold procedures?  After all,
> > Scheme has such procedures as well (SRFI 1 and R6RS).
>
> (CC'ing the mail list.)
>
> SRFI 1 specifies:
>
>   fold kons knil clist1 clist2 ... -> value
>
>      The fundamental list iterator.
>
>      First, consider the single list-parameter case. If clist1 = (e1 e2
> ... en), then this procedure returns
>      (kons en ... (kons e2 (kons e1 knil)) ... )
>
> So kons is called with the elements of the list as the left argument.
>
> The same is true for fold-right.
>
> In SRFI 231, as in Haskell and Ocaml, as I understand it, foldl calls
> kons with the list element as the right argument, and foldr calls kons
> with the list element as the left argument.
>
> R6RS has `fold-left` and `fold-right` with the same conventions as you have.  No need to cite a different language (with quite different evaluation semantics in the case of Haskell).
>
> SRFI 1's `fold` is R6RS's `fold-right` with the exchanged order when calling the combiner.
>
> Any comment about this? (Or did I miss one?)
>
> In view of established names in the Scheme world, `fold-left` and `fold-right` seem to be better choices than `foldl` and `foldr`.  (And everyone who knows `fold-left` and `fold-right` can automatically guess how the argument order is in SRFI 231.)

I made no comment.

As far as I can see, SRFI 1’s “fold” is R6RS’s fold-left with the knil as the rightmost argument of the combiner, not the leftmost.

I don’t attach too much importance to this small mistake, except that I find the plethora of competing fold/fold-left/fold-right in the Scheme world quite confusing, and I don’t want to propagate that confusion with this SRFI.

Hence my attempt to step outside the Scheme world for motivation; that both Haskell and Ocaml have the same semantics for these operations (modulo lazy versus eager evaluation of arguments) was only a bonus.

I also didn’t want people to think that array-fold-left in SRFI 231 was simply a renaming of array-fold in SRFI 179, which might only add to the confusion.

Because R6RS seems to have the same semantics for fold-left and fold-right as this SRFI, and because array-fold-right in SRFI 179 has the same definition as array-fold-right in SRFI 231 with one array argument, I may make the changes you suggest, I’ll have to think about it.

Brad