[Issue 8755] Change the order of reduce arguments

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 20 18:28:47 PDT 2014


https://d.puremagic.com/issues/show_bug.cgi?id=8755



--- Comment #14 from bearophile_hugs at eml.cc 2014-03-20 18:28:41 PDT ---
>Furthermore, it also improves usability by making the seeds passed by parameter pack, instead of forcing the use of a tuple.<

OK. (Despite in a modern language tuples should be built-in, so using them
should be natural, common, and syntactically very cheap. In
Python/Haskell/Scala code you don't see functions that refrain from accepting a
tuple).


>Finally, it allows using only 1 seed, in which case, the same seed is replicated and is used for all the functions.<

This is from the unittests:

    // Compute sum and sum of squares in one pass.
    // This can be used to compute get the average and standard deviation.
    // A single seed (0.0) is passed, but it is optional
    // if the range is not empty.
    r = a.fold!("a + b", "a + b * b")(0.0);
    assert(approxEqual(r[0], 35));  // sum
    assert(approxEqual(r[1], 233)); // sum of squares

This is ambiguous, it seems that "a + b" has a seed while "a + b * b" doesn't
have a seed. So in my opinion if you give N function then you need to give 0
seeds, or one N-tuple, or N seeds. So I don't like this.


>Oh yeah, also, I made it so that when no seed is given, it is an Error to use an empty range. This is the only case of deviation, but I think having nothrow justifies it.<

I am not sure this is a good idea. Throwing when you give no seed is probably
acceptable. But I am not sure.


> "iterables" are not supported anymore.

I don't understand what this means.

The ddocs of fold say:

>Note: $(D fold) replaces $(D reduce): It retains the same functionality and
behavior, but uses an updated and more convenient interface.<

So you retain the same functionality or you don't.

If by "iterables" you mean that fold doesn't accept opApply-based iterables
then I am against this change, I have plenty of code that opApply-based and I
sometimes use reduce on them.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list