emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7ca865d: Add `cl-constantly' function


From: Lars Ingebrigtsen
Subject: master 7ca865d: Add `cl-constantly' function
Date: Thu, 2 Dec 2021 04:19:53 -0500 (EST)

branch: master
commit 7ca865dc52a31374c68dc870246353db5acc023c
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add `cl-constantly' function
    
    * lisp/emacs-lisp/cl-lib.el (cl-constantly): Add Common Lisp
    function missing (bug#21584).
---
 lisp/emacs-lisp/cl-lib.el            | 5 +++++
 test/lisp/emacs-lisp/cl-lib-tests.el | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el
index 317a4c6..b01a32c 100644
--- a/lisp/emacs-lisp/cl-lib.el
+++ b/lisp/emacs-lisp/cl-lib.el
@@ -560,4 +560,9 @@ of record objects."
    (t
     (advice-remove 'type-of #'cl--old-struct-type-of))))
 
+(defun cl-constantly (value)
+  "Return a function that takes any number of arguments, but returns VALUE."
+  (lambda (&rest _)
+    value))
+
 ;;; cl-lib.el ends here
diff --git a/test/lisp/emacs-lisp/cl-lib-tests.el 
b/test/lisp/emacs-lisp/cl-lib-tests.el
index 854e371..a0facc8 100644
--- a/test/lisp/emacs-lisp/cl-lib-tests.el
+++ b/test/lisp/emacs-lisp/cl-lib-tests.el
@@ -551,4 +551,9 @@
     (should cl-old-struct-compat-mode)
     (cl-old-struct-compat-mode (if saved 1 -1))))
 
+(ert-deftest cl-constantly ()
+  (should (equal (mapcar (cl-constantly 3) '(a b c d))
+                 '(3 3 3 3))))
+
+
 ;;; cl-lib-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]