summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/cl-lib.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/cl-lib.el')
-rw-r--r--lisp/emacs-lisp/cl-lib.el155
1 files changed, 87 insertions, 68 deletions
diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el
index 3f7ca28d2bb..2bab451dd0c 100644
--- a/lisp/emacs-lisp/cl-lib.el
+++ b/lisp/emacs-lisp/cl-lib.el
@@ -105,29 +105,27 @@ a future Emacs interpreter will be able to use it.")
;; can safely be used in init files.
;;;###autoload
-(defmacro cl-incf (place &optional x)
+(defalias 'cl-incf #'incf
"Increment PLACE by X (1 by default).
PLACE may be a symbol, or any generalized variable allowed by `setf'.
The return value is the incremented value of PLACE.
If X is specified, it should be an expression that should
-evaluate to a number."
- (declare (debug (place &optional form)))
- (if (symbolp place)
- (list 'setq place (if x (list '+ place x) (list '1+ place)))
- (list 'cl-callf '+ place (or x 1))))
+evaluate to a number.
+
+This macro is considered deprecated in favor of the built-in macro
+`incf' that was added in Emacs 31.1.")
-(defmacro cl-decf (place &optional x)
+(defalias 'cl-decf #'decf
"Decrement PLACE by X (1 by default).
PLACE may be a symbol, or any generalized variable allowed by `setf'.
The return value is the decremented value of PLACE.
If X is specified, it should be an expression that should
-evaluate to a number."
- (declare (debug cl-incf))
- (if (symbolp place)
- (list 'setq place (if x (list '- place x) (list '1- place)))
- (list 'cl-callf '- place (or x 1))))
+evaluate to a number.
+
+This macro is considered deprecated in favor of the built-in macro
+`decf' that was added in Emacs 31.1.")
(defmacro cl-pushnew (x place &rest keys)
"Add X to the list stored in PLACE unless X is already in the list.
@@ -164,9 +162,9 @@ to an element already in the list stored in PLACE.
val))
(defun cl--set-substring (str start end val)
- (if end (if (< end 0) (cl-incf end (length str)))
+ (if end (if (< end 0) (incf end (length str)))
(setq end (length str)))
- (if (< start 0) (cl-incf start (length str)))
+ (if (< start 0) (incf start (length str)))
(concat (and (> start 0) (substring str 0 start))
val
(and (< end (length str)) (substring str end))))
@@ -185,8 +183,8 @@ to an element already in the list stored in PLACE.
;;; Blocks and exits.
-(defalias 'cl--block-wrapper 'identity)
-(defalias 'cl--block-throw 'throw)
+(defalias 'cl--block-wrapper #'identity)
+(defalias 'cl--block-throw #'throw)
;;; Multiple values.
@@ -232,7 +230,7 @@ right when EXPRESSION calls an ordinary Emacs Lisp function that returns just
one value."
(apply function expression))
-(defalias 'cl-multiple-value-call 'apply
+(defalias 'cl-multiple-value-call #'apply
"Apply FUNCTION to ARGUMENTS, taking multiple values into account.
This implementation only handles the case where there is only one argument.")
@@ -270,21 +268,29 @@ so that they are registered at compile-time as well as run-time."
(define-obsolete-function-alias 'cl-floatp-safe 'floatp "24.4")
-(defsubst cl-plusp (number)
- "Return t if NUMBER is positive."
- (> number 0))
+(defalias 'cl-plusp #'plusp
+ "Return t if NUMBER is positive.
+
+This function is considered deprecated in favor of the built-in function
+`plusp' that was added in Emacs 31.1.")
-(defsubst cl-minusp (number)
- "Return t if NUMBER is negative."
- (< number 0))
+(defalias 'cl-minusp #'minusp
+ "Return t if NUMBER is negative.
-(defun cl-oddp (integer)
- "Return t if INTEGER is odd."
- (eq (logand integer 1) 1))
+This function is considered deprecated in favor of the built-in function
+`minusp' that was added in Emacs 31.1.")
-(defun cl-evenp (integer)
- "Return t if INTEGER is even."
- (eq (logand integer 1) 0))
+(defalias 'cl-oddp #'oddp
+ "Return t if INTEGER is odd.
+
+This function is considered deprecated in favor of the built-in function
+`oddp' that was added in Emacs 31.1.")
+
+(defalias 'cl-evenp #'evenp
+ "Return t if INTEGER is even.
+
+This function is considered deprecated in favor of the built-in function
+`evenp' that was added in Emacs 31.1.")
(defconst cl-digit-char-table
(let* ((digits (make-vector 256 nil))
@@ -352,7 +358,7 @@ Call `cl-float-limits' to set this.")
;;; Sequence functions.
-(cl--defalias 'cl-copy-seq 'copy-sequence)
+(cl--defalias 'cl-copy-seq #'copy-sequence)
(declare-function cl--mapcar-many "cl-extra" (cl-func cl-seqs &optional acc))
@@ -363,6 +369,7 @@ and mapping stops as soon as the shortest list runs out. With just one
SEQ, this is like `mapcar'. With several, it is like the Common Lisp
`mapcar' function extended to arbitrary sequence types.
\n(fn FUNCTION SEQ...)"
+ (declare (important-return-value t))
(if cl-rest
(if (or (cdr cl-rest) (nlistp cl-x) (nlistp (car cl-rest)))
(cl--mapcar-many cl-func (cons cl-x cl-rest) 'accumulate)
@@ -372,78 +379,84 @@ SEQ, this is like `mapcar'. With several, it is like the Common Lisp
(nreverse cl-res)))
(mapcar cl-func cl-x)))
-(cl--defalias 'cl-svref 'aref)
+(cl--defalias 'cl-svref #'aref)
;;; List functions.
-(cl--defalias 'cl-first 'car)
-(cl--defalias 'cl-second 'cadr)
-(cl--defalias 'cl-rest 'cdr)
+(cl--defalias 'cl-first #'car)
+(cl--defalias 'cl-second #'cadr)
+(cl--defalias 'cl-rest #'cdr)
(cl--defalias 'cl-third #'caddr "Return the third element of the list X.")
(cl--defalias 'cl-fourth #'cadddr "Return the fourth element of the list X.")
(defsubst cl-fifth (x)
"Return the fifth element of the list X."
- (declare (gv-setter (lambda (store) `(setcar (nthcdr 4 ,x) ,store))))
+ (declare (side-effect-free t)
+ (gv-setter (lambda (store) `(setcar (nthcdr 4 ,x) ,store))))
(nth 4 x))
(defsubst cl-sixth (x)
"Return the sixth element of the list X."
- (declare (gv-setter (lambda (store) `(setcar (nthcdr 5 ,x) ,store))))
+ (declare (side-effect-free t)
+ (gv-setter (lambda (store) `(setcar (nthcdr 5 ,x) ,store))))
(nth 5 x))
(defsubst cl-seventh (x)
"Return the seventh element of the list X."
- (declare (gv-setter (lambda (store) `(setcar (nthcdr 6 ,x) ,store))))
+ (declare (side-effect-free t)
+ (gv-setter (lambda (store) `(setcar (nthcdr 6 ,x) ,store))))
(nth 6 x))
(defsubst cl-eighth (x)
"Return the eighth element of the list X."
- (declare (gv-setter (lambda (store) `(setcar (nthcdr 7 ,x) ,store))))
+ (declare (side-effect-free t)
+ (gv-setter (lambda (store) `(setcar (nthcdr 7 ,x) ,store))))
(nth 7 x))
(defsubst cl-ninth (x)
"Return the ninth element of the list X."
- (declare (gv-setter (lambda (store) `(setcar (nthcdr 8 ,x) ,store))))
+ (declare (side-effect-free t)
+ (gv-setter (lambda (store) `(setcar (nthcdr 8 ,x) ,store))))
(nth 8 x))
(defsubst cl-tenth (x)
"Return the tenth element of the list X."
- (declare (gv-setter (lambda (store) `(setcar (nthcdr 9 ,x) ,store))))
+ (declare (side-effect-free t)
+ (gv-setter (lambda (store) `(setcar (nthcdr 9 ,x) ,store))))
(nth 9 x))
-(defalias 'cl-caaar 'caaar)
-(defalias 'cl-caadr 'caadr)
-(defalias 'cl-cadar 'cadar)
-(defalias 'cl-caddr 'caddr)
-(defalias 'cl-cdaar 'cdaar)
-(defalias 'cl-cdadr 'cdadr)
-(defalias 'cl-cddar 'cddar)
-(defalias 'cl-cdddr 'cdddr)
-(defalias 'cl-caaaar 'caaaar)
-(defalias 'cl-caaadr 'caaadr)
-(defalias 'cl-caadar 'caadar)
-(defalias 'cl-caaddr 'caaddr)
-(defalias 'cl-cadaar 'cadaar)
-(defalias 'cl-cadadr 'cadadr)
-(defalias 'cl-caddar 'caddar)
-(defalias 'cl-cadddr 'cadddr)
-(defalias 'cl-cdaaar 'cdaaar)
-(defalias 'cl-cdaadr 'cdaadr)
-(defalias 'cl-cdadar 'cdadar)
-(defalias 'cl-cdaddr 'cdaddr)
-(defalias 'cl-cddaar 'cddaar)
-(defalias 'cl-cddadr 'cddadr)
-(defalias 'cl-cdddar 'cdddar)
-(defalias 'cl-cddddr 'cddddr)
+(defalias 'cl-caaar #'caaar)
+(defalias 'cl-caadr #'caadr)
+(defalias 'cl-cadar #'cadar)
+(defalias 'cl-caddr #'caddr)
+(defalias 'cl-cdaar #'cdaar)
+(defalias 'cl-cdadr #'cdadr)
+(defalias 'cl-cddar #'cddar)
+(defalias 'cl-cdddr #'cdddr)
+(defalias 'cl-caaaar #'caaaar)
+(defalias 'cl-caaadr #'caaadr)
+(defalias 'cl-caadar #'caadar)
+(defalias 'cl-caaddr #'caaddr)
+(defalias 'cl-cadaar #'cadaar)
+(defalias 'cl-cadadr #'cadadr)
+(defalias 'cl-caddar #'caddar)
+(defalias 'cl-cadddr #'cadddr)
+(defalias 'cl-cdaaar #'cdaaar)
+(defalias 'cl-cdaadr #'cdaadr)
+(defalias 'cl-cdadar #'cdadar)
+(defalias 'cl-cdaddr #'cdaddr)
+(defalias 'cl-cddaar #'cddaar)
+(defalias 'cl-cddadr #'cddadr)
+(defalias 'cl-cdddar #'cdddar)
+(defalias 'cl-cddddr #'cddddr)
;;(defun last* (x &optional n)
;; "Returns the last link in the list LIST.
;;With optional argument N, returns Nth-to-last link (default 1)."
;; (if n
;; (let ((m 0) (p x))
-;; (while (consp p) (cl-incf m) (pop p))
+;; (while (consp p) (incf m) (pop p))
;; (if (<= n 0) p
;; (if (< n m) (nthcdr (- m n) x) x)))
;; (while (consp (cdr x)) (pop x))
@@ -454,7 +467,8 @@ SEQ, this is like `mapcar'. With several, it is like the Common Lisp
Thus, `(cl-list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to
`(cons A (cons B (cons C D)))'.
\n(fn ARG...)"
- (declare (compiler-macro cl--compiler-macro-list*))
+ (declare (side-effect-free error-free)
+ (compiler-macro cl--compiler-macro-list*))
(cond ((not rest) arg)
((not (cdr rest)) (cons arg (car rest)))
(t (let* ((n (length rest))
@@ -465,6 +479,7 @@ Thus, `(cl-list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to
(defun cl-ldiff (list sublist)
"Return a copy of LIST with the tail SUBLIST removed."
+ (declare (side-effect-free t))
(let ((res nil))
(while (and (consp list) (not (eq list sublist)))
(push (pop list) res))
@@ -492,7 +507,8 @@ The elements of LIST are not copied, just the list structure itself."
Otherwise, return LIST unmodified.
\nKeywords supported: :test :test-not :key
\n(fn ITEM LIST [KEYWORD VALUE]...)"
- (declare (compiler-macro cl--compiler-macro-adjoin))
+ (declare (important-return-value t)
+ (compiler-macro cl--compiler-macro-adjoin))
(cond ((or (equal cl-keys '(:test eq))
(and (null cl-keys) (not (numberp cl-item))))
(if (memq cl-item cl-list) cl-list (cons cl-item cl-list)))
@@ -505,6 +521,7 @@ Otherwise, return LIST unmodified.
Return a copy of TREE with all elements `eql' to OLD replaced by NEW.
\nKeywords supported: :test :test-not :key
\n(fn NEW OLD TREE [KEYWORD VALUE]...)"
+ (declare (important-return-value t))
(if (or cl-keys (and (numberp cl-old) (not (integerp cl-old))))
(apply 'cl-sublis (list (cons cl-old cl-new)) cl-tree cl-keys)
(cl--do-subst cl-new cl-old cl-tree)))
@@ -518,9 +535,10 @@ Return a copy of TREE with all elements `eql' to OLD replaced by NEW.
cl-tree (cons a d))))
(t cl-tree)))
-(defun cl-acons (key value alist)
+(defsubst cl-acons (key value alist)
"Add KEY and VALUE to ALIST.
Return a new list with (cons KEY VALUE) as car and ALIST as cdr."
+ (declare (side-effect-free error-free))
(cons (cons key value) alist))
(defun cl-pairlis (keys values &optional alist)
@@ -528,6 +546,7 @@ Return a new list with (cons KEY VALUE) as car and ALIST as cdr."
Return a new alist composed by associating KEYS to corresponding VALUES;
the process stops as soon as KEYS or VALUES run out.
If ALIST is non-nil, the new pairs are prepended to it."
+ (declare (side-effect-free t))
(nconc (cl-mapcar 'cons keys values) alist))
;;; Miscellaneous.