* 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)
@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
(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
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.
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
: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)))
(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)))
(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)))
(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)))