]> git.eshelyaron.com Git - emacs.git/commitdiff
New functions oddp and evenp
authorStefan Kangas <stefankangas@gmail.com>
Sun, 16 Feb 2025 23:52:45 +0000 (00:52 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 18 Feb 2025 08:50:09 +0000 (09:50 +0100)
* lisp/emacs-lisp/cl-lib.el (cl-oddp, cl-evenp): Move from here...
* lisp/subr.el (oddp, evenp): ...to here.  Make old names into
aliases, documented as deprecated.  Add type declarations.
* lisp/obsolete/cl.el: Don't alias oddp and evenp.

* test/lisp/emacs-lisp/cl-lib-tests.el (cl-lib-test-oddp)
(cl-lib-test-evenp): Move tests from here...
* test/lisp/subr-tests.el (subr-test-oddp, subr-test-evenp): ...to here.
* lisp/emacs-lisp/shortdoc.el (number): Add oddp and evenp.
(map): Prefer oddp and evenp to cl-oddp and cl-evenp.

* doc/lispref/numbers.texi (Predicates on Numbers): Document above new
functions oddp and evenp.
* doc/misc/cl.texi (Predicates on Numbers): Delete cl-oddp and cl-evenp.
(Other Clauses): Prefer oddp to cl-oddp.

(cherry picked from commit 667d011410d1ab53fb90a497eb07f0b65c933821)

doc/lispref/numbers.texi
doc/misc/cl.texi
lisp/emacs-lisp/shortdoc.el
test/lisp/emacs-lisp/cl-lib-tests.el
test/lisp/subr-tests.el

index fc52f11cf4a004bb75869863ddecb43fa1bb1235..ee43389399a6e574885d62da9fc7adefc5d01d3a 100644 (file)
@@ -409,6 +409,16 @@ if so, @code{nil} otherwise.  The argument must be a number.
 @code{(zerop x)} is equivalent to @code{(= x 0)}.
 @end defun
 
+@defun oddp integer
+This predicate tests whether its argument is an odd number, and returns
+@code{t} if so, @code{nil} otherwise.  The argument must be an integer.
+@end defun
+
+@defun evenp integer
+This predicate tests whether its argument is an even number, and returns
+@code{t} if so, @code{nil} otherwise.  The argument must be an integer.
+@end defun
+
 @node Comparison of Numbers
 @section Comparison of Numbers
 @cindex number comparison
index fbed1265aa31923932825e3fd08dc5542126b54b..f481f6f2721714ca8de43bdace3746e690695124 100644 (file)
@@ -2450,7 +2450,7 @@ by the name @code{it} in the ``then'' part.  For example:
 (setq funny-numbers '(6 13 -1))
      @result{} (6 13 -1)
 (cl-loop for x below 10
-         if (cl-oddp x)
+         if (oddp x)
            collect x into odds
            and if (memq x funny-numbers) return (cdr it) end
          else
@@ -3055,7 +3055,7 @@ This section defines a few simple Common Lisp operations on numbers
 that were left out of Emacs Lisp.
 
 @menu
-* Predicates on Numbers::       @code{cl-plusp}, @code{cl-oddp}, etc.
+* Predicates on Numbers::       @code{cl-plusp}, @code{cl-minusp}, etc.
 * Numerical Functions::         @code{cl-floor}, @code{cl-ceiling}, etc.
 * Random Numbers::              @code{cl-random}, @code{cl-make-random-state}.
 * Implementation Parameters::   @code{cl-most-positive-float}, etc.
@@ -3078,16 +3078,6 @@ This predicate tests whether @var{number} is negative.  It is an
 error if the argument is not a number.
 @end defun
 
-@defun cl-oddp integer
-This predicate tests whether @var{integer} is odd.  It is an
-error if the argument is not an integer.
-@end defun
-
-@defun cl-evenp integer
-This predicate tests whether @var{integer} is even.  It is an
-error if the argument is not an integer.
-@end defun
-
 @defun cl-digit-char-p char radix
 Test if @var{char} is a digit in the specified @var{radix} (default is
 10).  If it is, return the numerical value of digit @var{char} in
index cc9971b232f7bb8c15819a5e69302b6c37bea56b..af995123dc5353910cfed3050f5647831c9638eb 100644 (file)
@@ -278,17 +278,17 @@ A FUNC form can have any number of `:no-eval' (or `:no-value'),
    :args (function map)
    :eval (map-values-apply #'1+ (list '(1 . 2)  '(3 . 4))))
   (map-filter
-   :eval (map-filter (lambda (k _) (cl-oddp k)) (list '(1 . 2) '(4 . 6)))
-   :eval (map-filter (lambda (k v) (cl-evenp (+ k v))) (list '(1 . 2) '(4 . 6))))
+   :eval (map-filter (lambda (k _) (oddp k)) (list '(1 . 2) '(4 . 6)))
+   :eval (map-filter (lambda (k v) (evenp (+ k v))) (list '(1 . 2) '(4 . 6))))
   (map-remove
-   :eval (map-remove (lambda (k _) (cl-oddp k)) (list '(1 . 2) '(4 . 6)))
-   :eval (map-remove (lambda (k v) (cl-evenp (+ k v))) (list '(1 . 2) '(4 . 6))))
+   :eval (map-remove (lambda (k _) (oddp k)) (list '(1 . 2) '(4 . 6)))
+   :eval (map-remove (lambda (k v) (evenp (+ k v))) (list '(1 . 2) '(4 . 6))))
   (map-some
-   :eval (map-some (lambda (k _) (cl-oddp k)) (list '(1 . 2) '(4 . 6)))
-   :eval (map-some (lambda (k v) (cl-evenp (+ k v))) (list '(1 . 2) '(4 . 6))))
+   :eval (map-some (lambda (k _) (oddp k)) (list '(1 . 2) '(4 . 6)))
+   :eval (map-some (lambda (k v) (evenp (+ k v))) (list '(1 . 2) '(4 . 6))))
   (map-every-p
-   :eval (map-every-p (lambda (k _) (cl-oddp k)) (list '(1 . 2) '(4 . 6)))
-   :eval (map-every-p (lambda (k v) (cl-evenp (+ k v))) (list '(1 . 3) '(4 . 6))))
+   :eval (map-every-p (lambda (k _) (oddp k)) (list '(1 . 2) '(4 . 6)))
+   :eval (map-every-p (lambda (k v) (evenp (+ k v))) (list '(1 . 3) '(4 . 6))))
   "Combining and changing maps"
   (map-merge
    :eval (map-merge 'alist '(1 2 3 4) #s(hash-table data (5 6 7 8)))
@@ -1418,10 +1418,10 @@ A FUNC form can have any number of `:no-eval' (or `:no-value'),
   (cl-minusp
    :eval (cl-minusp 0)
    :eval (cl-minusp -1))
-  (cl-oddp
-   :eval (cl-oddp 3))
-  (cl-evenp
-   :eval (cl-evenp 6))
+  (oddp
+   :eval (oddp 3))
+  (evenp
+   :eval (evenp 6))
   (bignump
    :eval (bignump 4)
    :eval (bignump (expt 2 90)))
index 12de268bceddaf522ef018cf8113104aa3f34428..4121c1bfdb0b72e82d37c31fe9bcb4f956097832 100644 (file)
   (should-not (cl-minusp 1.0e+INF))
   (should-error (cl-minusp "-42") :type 'wrong-type-argument))
 
-(ert-deftest cl-lib-test-oddp ()
-  (should (cl-oddp -3))
-  (should (cl-oddp 3))
-  (should-not (cl-oddp -2))
-  (should-not (cl-oddp 0))
-  (should-not (cl-oddp 2))
-  (should-error (cl-oddp 3.0e+NaN) :type 'wrong-type-argument)
-  (should-error (cl-oddp 3.0) :type 'wrong-type-argument)
-  (should-error (cl-oddp "3") :type 'wrong-type-argument))
-
-(ert-deftest cl-lib-test-evenp ()
-  (should (cl-evenp -2))
-  (should (cl-evenp 0))
-  (should (cl-evenp 2))
-  (should-not (cl-evenp -3))
-  (should-not (cl-evenp 3))
-  (should-error (cl-evenp 2.0e+NaN) :type 'wrong-type-argument)
-  (should-error (cl-evenp 2.0) :type 'wrong-type-argument)
-  (should-error (cl-evenp "2") :type 'wrong-type-argument))
-
 (ert-deftest cl-digit-char-p ()
   (should (eql 3 (cl-digit-char-p ?3)))
   (should (eql 10 (cl-digit-char-p ?a 11)))
index 29767ed07b5ce441f2f629cd22f0e72ccdfea977..1b209ab6383e510f2c6a2a965e73c2ed275e09c5 100644 (file)
   (should-not (zerop (1- most-negative-fixnum)))
   (should-error (zerop "-5") :type 'wrong-type-argument))
 
+(ert-deftest subr-test-oddp ()
+  (should (oddp -3))
+  (should (oddp 3))
+  (should-not (oddp -2))
+  (should-not (oddp 0))
+  (should-not (oddp 2))
+  (should-error (oddp 3.0e+NaN) :type 'wrong-type-argument)
+  (should-error (oddp 3.0) :type 'wrong-type-argument)
+  (should-error (oddp "3") :type 'wrong-type-argument))
+
+(ert-deftest subr-test-evenp ()
+  (should (evenp -2))
+  (should (evenp 0))
+  (should (evenp 2))
+  (should-not (evenp -3))
+  (should-not (evenp 3))
+  (should-error (evenp 2.0e+NaN) :type 'wrong-type-argument)
+  (should-error (evenp 2.0) :type 'wrong-type-argument)
+  (should-error (evenp "2") :type 'wrong-type-argument))
+
 (ert-deftest let-when-compile ()
   ;; good case
   (should (equal (macroexpand '(let-when-compile ((foo (+ 2 3)))