Email list hosting service & mailing list manager

Implementation of reduce-right in SRFI 1 TAKIZAWA Yozo (28 Dec 2021 08:50 UTC)
Re: Implementation of reduce-right in SRFI 1 Arthur A. Gleckler (08 Jan 2022 16:47 UTC)
Re: Implementation of reduce-right in SRFI 1 Alex Shinn (09 Jan 2022 23:20 UTC)
Re: Implementation of reduce-right in SRFI 1 John Cowan (10 Jan 2022 04:13 UTC)
Re: Implementation of reduce-right in SRFI 1 Alex Shinn (10 Jan 2022 04:43 UTC)
Re: Implementation of reduce-right in SRFI 1 Marc Nieper-Wißkirchen (10 Jan 2022 12:02 UTC)
Re: Implementation of reduce-right in SRFI 1 Arthur A. Gleckler (10 Jan 2022 16:31 UTC)
Re: Implementation of reduce-right in SRFI 1 Arthur A. Gleckler (23 Oct 2022 01:45 UTC)
Re: Implementation of reduce-right in SRFI 1 TAKIZAWA Yozo (10 Jan 2022 11:54 UTC)

Re: Implementation of reduce-right in SRFI 1 Alex Shinn 09 Jan 2022 23:20 UTC

This was from an issue first reported in Chibi.

The definition of `reduce` is quite clear that it only uses the
`ridentity` in the empty list case.
It further provides a detailed note explaining this and the motivation.

The definition of `reduce-right` both in the expansions given and the summary:

  "... in other words, we compute (fold-right f ridentity list)"

seems to make it clear that the ridentity is used even in the
non-empty list case.

However, this makes no sense, because then there is no difference
between fold-right and reduce-right.
I think it's clear the same note was intended for reduce-right as for reduce.

Also, the reduce-right definition incorrectly expands into reduce:

  (reduce-right f ridentity '(e1 e2 ...)) =
    (f e1 (reduce f ridentity (e2 ...)))

At least there should be an errata to replace that expansion with
`reduce-right`.
Arguably it should be modified further:

  (reduce-right f ridentity '(e1 e2 ...)) =
    (fold-right f e1 (e2 ...))

updating the summary to something like

  "... in other words, we compute (fold-right f ridentity list), but
as with reduce only use ridentity in the empty list case."

--
Alex

On Sun, Jan 9, 2022 at 1:48 AM Arthur A. Gleckler <xxxxxx@speechcode.com> wrote:
>
> On Tue, Dec 28, 2021 at 12:50 AM TAKIZAWA Yozo <xxxxxx@nbk.bz> wrote:
>>
>> Although this is not a specification topic but implementation, I send
>> it to the list as a related issue to confirm or clarify.
>
>
> Thanks for the question.  Would you mind showing some examples to make the question clearer?  It would be great if you could show examples that differ between Scheme implementations.
>
> Thanks, and happy new year.