]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/cl-seq.el
Better documentation for cl-reduce (bug#24014)
[gnu-emacs] / lisp / emacs-lisp / cl-seq.el
index 61ee5698435ec9c7217ed4e01b89841902fa133b..443a147b3d223badf4ef406670df77cb3eda70d9 100644 (file)
 (defun cl-reduce (cl-func cl-seq &rest cl-keys)
   "Reduce two-argument FUNCTION across SEQ.
 \nKeywords supported:  :start :end :from-end :initial-value :key
+
+Return the result of calling FUNCTION with the first and the
+second element of SEQ, then calling FUNCTION with that result and
+the third element of SEQ, then with that result and the fourth
+element of SEQ, etc.
+
+If :INITIAL-VALUE is specified, it is added to the front of SEQ.
+If SEQ is empty, return :INITIAL-VALUE and FUNCTION is not
+called.
+
 \n(fn FUNCTION SEQ [KEYWORD VALUE]...)"
   (cl--parsing-keywords (:from-end (:start 0) :end :initial-value :key) ()
     (or (listp cl-seq) (setq cl-seq (append cl-seq nil)))
@@ -774,7 +784,7 @@ to avoid corrupting the original LIST1 and LIST2.
 \nKeywords supported:  :test :test-not :key
 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)"
   (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1)
-       ((equal cl-list1 cl-list2) cl-list1)
+       ((and (not cl-keys) (equal cl-list1 cl-list2)) cl-list1)
        (t
         (or (>= (length cl-list1) (length cl-list2))
             (setq cl-list1 (prog1 cl-list2 (setq cl-list2 cl-list1))))