Subject: bug#37400: Patch for bug in cl-reduce: function called with no arguments when list is empty

From: Noam Postavsky <[email-masked]>
Date: Fri, 13 Sep 2019 11:18:27 -0400

Adrià Garriga <[email-masked]> writes:

> +(ert-deftest cl-seq-reduce ()
> +  (let ((bad-add (lambda (x y) (+ x y))))
> +    (should-not (cl-reduce bad-add nil))

Actually, I think it's a docstring bug.  The Common Lisp Hyperspec says:

    If the subsequence is empty and no initial-value is given, then the
    function is called with zero arguments, and reduce returns whatever
    function does. This is the only case where the function is called
    with other than two arguments.

It looks like Emacs' current implementation is correct, but the
docstring doesn't explain it accurately.

https://www.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/Body/fun_reduce.html