Am Fr., 23. Sept. 2022 um 19:22 Uhr schrieb John Cowan <[email protected]>:

> What I'd like to do is this:
>
> For all sequences, provide either `fold` and `fold-right` with SRFI 1
> conventions (the accumulation is the rightmost argument) or `foldl` and
> `foldr` with SRFI 43 conventions (accumulator is the leftmost argument).
>

That would be most confusing because `foldr` with the accumulator as the
leftmost argument is neither what Haskell/OCaml do, nor what R6RS does, nor
what SRFI 1 does, nor what SRFI 231 should be doing given Bradley's
rationale concerning left- and right operations (in the mathematical sense).

Adding SRFI 43 to the mix does not help because SRFI 43's naming
conventions are already incompatible with SRFI 1 (and, for that matter,
R6RS).  In particular, when SRFI 43 and descendants are on the list of the
cleanup committee.

Marc


> Currently all the vector-like SRFIs use SRFI 43 conventions with the names
> `fold` and `right-fold` as a consequence of being textually descended from
> SRFI 43, so these SRFIs would be changed incompatibly, but at least it is
> not a silent breaking change.
>
> I say "leftmost" and "rightmost" because folds over dictionaries pass
> three arguments to the folding function: (key value accumulation).
>
> On Fri, Sep 23, 2022 at 5:25 AM Marc Nieper-Wißkirchen <
> [email protected]> wrote:
>
>> Am Do., 22. Sept. 2022 um 23:14 Uhr schrieb Lucier, Bradley J <
>> [email protected]>:
>>
>> [...]
>>
>> > 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.
>>>
>>
>> As far as R6RS, SRFI 1, and naming conventions established by other
>> functional languages are concerned, everything is fine, I think.
>>
>> R6RS defines `fold-left` and `fold-right` in the style of `foldl` and
>> `foldr` of other functional programming languages (but with a more verbose
>> name as typical for Scheme).
>>
>> SRFI 1 offers `fold` as an alternative to `fold-left` with the arguments
>> exchanged for the combiner.
>>
>> [...]
>>
>> 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.
>>>
>>
>> Thanks,
>>
>> Marc
>>
>>

Reply via email to