All this discussion of "identity" defaults for reductions has been very interesting and enlightening.

But it seems to me that the simplest "correct" behaviour for reductions is:

    2+ args: interpolate specified operator
    1 arg:   return that arg
    0 args:  fail (i.e. thrown or unthrown exception depending on use fatal)

Then, as Brad previously reminded us all, to cover the possibility of empty arg lists, you just prepend the desired identity value:

    $sum  = [+] 0, @values;
    $prod = [*] 1, @values;
    $prob = [*] 0, @probs;

or else, as Stuart observed, postpend them as a default:

    $sum  = ([+] @values err 0);
    $prod = ([*] @values err 1);
    $prob = ([*] @probs  err 0);


Damian

Reply via email to