From: Stefan Monnier Date: Thu, 16 Nov 2023 14:50:45 +0000 (-0500) Subject: (merge-ordered-lists): Dot a few more `i`s X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=44b5761b44aee8d7864b5aab6c324d26de55914c;p=emacs.git (merge-ordered-lists): Dot a few more `i`s Suggested by Mattias EngdegÄrd. * lisp/subr.el (merge-ordered-lists): Don't mutate the arg. * test/lisp/subr-tests.el (subr-tests--merge-ordered-lists): Make the test a bit more precise. --- diff --git a/lisp/subr.el b/lisp/subr.el index abc937531ad..12f37d66ac1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2695,6 +2695,7 @@ By default we choose the head of the first list." ;; Algorithm inspired from ;; [C3](https://en.wikipedia.org/wiki/C3_linearization) (let ((result '())) + (setq lists (remq nil lists)) ;Don't mutate the original `lists' argument. (while (cdr (setq lists (delq nil lists))) ;; Try to find the next element of the result. This ;; is achieved by considering the first element of each diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index f67ac70046a..f485328aa7a 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -365,7 +365,7 @@ (defalias 'subr-tests--mode-C #'subr-tests--mode-B) (derived-mode-add-parents 'subr-tests--mode-A '(subr-tests--mode-C)) -(ert-deftest subt-tests--derived-mode-add-parents () +(ert-deftest subr-tests--derived-mode-add-parents () ;; The Right Answer is somewhat unclear in the presence of cycles, ;; but let's make sure we get tolerable answers. ;; FIXME: Currently `prog-mode' doesn't always end up at the end :-( @@ -381,12 +381,14 @@ '(subr-tests--mode-A subr-tests--mode-B prog-mode subr-tests--mode-C subr-tests--derived-mode-1)))))) -(ert-deftest subt-tests--merge-ordered-lists () +(ert-deftest subr-tests--merge-ordered-lists () (should (equal (merge-ordered-lists - '((B A) (C A) (D B) (E D C))) + '((B A) (C A) (D B) (E D C)) + (lambda (_) (error "cycle"))) '(E D B C A))) (should (equal (merge-ordered-lists - '((E D C) (B A) (C A) (D B))) + '((E D C) (B A) (C A) (D B)) + (lambda (_) (error "cycle"))) '(E D C B A))) (should-error (merge-ordered-lists '((E C D) (B A) (A C) (D B))