1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 14:30:50 -08:00

Use lexical-binding for all of CL, and clean up its namespace.

* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
This commit is contained in:
Stefan Monnier 2012-06-11 11:52:50 -04:00
parent 3017f87fbd
commit bb3faf5b98
10 changed files with 337 additions and 340 deletions

View file

@ -1,4 +1,4 @@
;;; cl-seq.el --- Common Lisp features, part 3
;;; cl-seq.el --- Common Lisp features, part 3 -*- lexical-binding: t -*-
;; Copyright (C) 1993, 2001-2012 Free Software Foundation, Inc.
@ -43,99 +43,91 @@
(require 'cl-lib)
;;; Keyword parsing. This is special-cased here so that we can compile
;;; this file independent from cl-macs.
;; Keyword parsing.
;; This is special-cased here so that we can compile
;; this file independent from cl-macs.
(defmacro cl-parsing-keywords (kwords other-keys &rest body)
(defmacro cl--parsing-keywords (kwords other-keys &rest body)
(declare (indent 2) (debug (sexp sexp &rest form)))
(cons
'let*
(cons (mapcar
(function
(lambda (x)
(let* ((var (if (consp x) (car x) x))
(mem (list 'car (list 'cdr (list 'memq (list 'quote var)
'cl-keys)))))
(if (eq var :test-not)
(setq mem (list 'and mem (list 'setq 'cl-test mem) t)))
(if (eq var :if-not)
(setq mem (list 'and mem (list 'setq 'cl-if mem) t)))
(list (intern
(format "cl-%s" (substring (symbol-name var) 1)))
(if (consp x) (list 'or mem (car (cdr x))) mem)))))
kwords)
(append
(and (not (eq other-keys t))
(list
(list 'let '((cl-keys-temp cl-keys))
(list 'while 'cl-keys-temp
(list 'or (list 'memq '(car cl-keys-temp)
(list 'quote
(mapcar
(function
(lambda (x)
(if (consp x)
(car x) x)))
(append kwords
other-keys))))
'(car (cdr (memq (quote :allow-other-keys)
cl-keys)))
'(error "Bad keyword argument %s"
(car cl-keys-temp)))
'(setq cl-keys-temp (cdr (cdr cl-keys-temp)))))))
body))))
`(let* ,(mapcar
(lambda (x)
(let* ((var (if (consp x) (car x) x))
(mem `(car (cdr (memq ',var cl-keys)))))
(if (eq var :test-not)
(setq mem `(and ,mem (setq cl-test ,mem) t)))
(if (eq var :if-not)
(setq mem `(and ,mem (setq cl-if ,mem) t)))
(list (intern
(format "cl-%s" (substring (symbol-name var) 1)))
(if (consp x) `(or ,mem ,(car (cdr x))) mem))))
kwords)
,@(append
(and (not (eq other-keys t))
(list
(list 'let '((cl-keys-temp cl-keys))
(list 'while 'cl-keys-temp
(list 'or (list 'memq '(car cl-keys-temp)
(list 'quote
(mapcar
(function
(lambda (x)
(if (consp x)
(car x) x)))
(append kwords
other-keys))))
'(car (cdr (memq (quote :allow-other-keys)
cl-keys)))
'(error "Bad keyword argument %s"
(car cl-keys-temp)))
'(setq cl-keys-temp (cdr (cdr cl-keys-temp)))))))
body)))
(defmacro cl-check-key (x)
(defmacro cl--check-key (x) ;Expects `cl-key' in context of generated code.
(declare (debug edebug-forms))
(list 'if 'cl-key (list 'funcall 'cl-key x) x))
`(if cl-key (funcall cl-key ,x) ,x))
(defmacro cl-check-test-nokey (item x)
(defmacro cl--check-test-nokey (item x) ;cl-test cl-if cl-test-not cl-if-not.
(declare (debug edebug-forms))
(list 'cond
(list 'cl-test
(list 'eq (list 'not (list 'funcall 'cl-test item x))
'cl-test-not))
(list 'cl-if
(list 'eq (list 'not (list 'funcall 'cl-if x)) 'cl-if-not))
(list 't (list 'if (list 'numberp item)
(list 'equal item x) (list 'eq item x)))))
`(cond
(cl-test (eq (not (funcall cl-test ,item ,x))
cl-test-not))
(cl-if (eq (not (funcall cl-if ,x)) cl-if-not))
(t (eql ,item ,x))))
(defmacro cl-check-test (item x)
(defmacro cl--check-test (item x) ;all of the above.
(declare (debug edebug-forms))
(list 'cl-check-test-nokey item (list 'cl-check-key x)))
`(cl--check-test-nokey ,item (cl--check-key ,x)))
(defmacro cl-check-match (x y)
(defmacro cl--check-match (x y) ;cl-key cl-test cl-test-not
(declare (debug edebug-forms))
(setq x (list 'cl-check-key x) y (list 'cl-check-key y))
(list 'if 'cl-test
(list 'eq (list 'not (list 'funcall 'cl-test x y)) 'cl-test-not)
(list 'if (list 'numberp x)
(list 'equal x y) (list 'eq x y))))
(setq x `(cl--check-key ,x) y `(cl--check-key ,y))
`(if cl-test
(eq (not (funcall cl-test ,x ,y)) cl-test-not)
(eql ,x ,y)))
(defvar cl-test) (defvar cl-test-not)
(defvar cl-if) (defvar cl-if-not)
(defvar cl-key)
;;;###autoload
(defun cl-reduce (cl-func cl-seq &rest cl-keys)
"Reduce two-argument FUNCTION across SEQ.
\nKeywords supported: :start :end :from-end :initial-value :key
\n(fn FUNCTION SEQ [KEYWORD VALUE]...)"
(cl-parsing-keywords (:from-end (:start 0) :end :initial-value :key) ()
(cl--parsing-keywords (:from-end (:start 0) :end :initial-value :key) ()
(or (listp cl-seq) (setq cl-seq (append cl-seq nil)))
(setq cl-seq (cl-subseq cl-seq cl-start cl-end))
(if cl-from-end (setq cl-seq (nreverse cl-seq)))
(let ((cl-accum (cond ((memq :initial-value cl-keys) cl-initial-value)
(cl-seq (cl-check-key (pop cl-seq)))
(cl-seq (cl--check-key (pop cl-seq)))
(t (funcall cl-func)))))
(if cl-from-end
(while cl-seq
(setq cl-accum (funcall cl-func (cl-check-key (pop cl-seq))
(setq cl-accum (funcall cl-func (cl--check-key (pop cl-seq))
cl-accum)))
(while cl-seq
(setq cl-accum (funcall cl-func cl-accum
(cl-check-key (pop cl-seq))))))
(cl--check-key (pop cl-seq))))))
cl-accum)))
;;;###autoload
@ -143,7 +135,7 @@
"Fill the elements of SEQ with ITEM.
\nKeywords supported: :start :end
\n(fn SEQ ITEM [KEYWORD VALUE]...)"
(cl-parsing-keywords ((:start 0) :end) ()
(cl--parsing-keywords ((:start 0) :end) ()
(if (listp seq)
(let ((p (nthcdr cl-start seq))
(n (if cl-end (- cl-end cl-start) 8000000)))
@ -164,14 +156,14 @@
SEQ1 is destructively modified, then returned.
\nKeywords supported: :start1 :end1 :start2 :end2
\n(fn SEQ1 SEQ2 [KEYWORD VALUE]...)"
(cl-parsing-keywords ((:start1 0) :end1 (:start2 0) :end2) ()
(cl--parsing-keywords ((:start1 0) :end1 (:start2 0) :end2) ()
(if (and (eq cl-seq1 cl-seq2) (<= cl-start2 cl-start1))
(or (= cl-start1 cl-start2)
(let* ((cl-len (length cl-seq1))
(cl-n (min (- (or cl-end1 cl-len) cl-start1)
(- (or cl-end2 cl-len) cl-start2))))
(while (>= (setq cl-n (1- cl-n)) 0)
(cl-set-elt cl-seq1 (+ cl-start1 cl-n)
(cl--set-elt cl-seq1 (+ cl-start1 cl-n)
(elt cl-seq2 (+ cl-start2 cl-n))))))
(if (listp cl-seq1)
(let ((cl-p1 (nthcdr cl-start1 cl-seq1))
@ -208,7 +200,7 @@ This is a non-destructive function; it makes a copy of SEQ if necessary
to avoid corrupting the original SEQ.
\nKeywords supported: :test :test-not :key :count :start :end :from-end
\n(fn ITEM SEQ [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :if :if-not :count :from-end
(cl--parsing-keywords (:test :test-not :key :if :if-not :count :from-end
(:start 0) :end) ()
(if (<= (or cl-count (setq cl-count 8000000)) 0)
cl-seq
@ -227,14 +219,14 @@ to avoid corrupting the original SEQ.
(setq cl-end (- (or cl-end 8000000) cl-start))
(if (= cl-start 0)
(while (and cl-seq (> cl-end 0)
(cl-check-test cl-item (car cl-seq))
(cl--check-test cl-item (car cl-seq))
(setq cl-end (1- cl-end) cl-seq (cdr cl-seq))
(> (setq cl-count (1- cl-count)) 0))))
(if (and (> cl-count 0) (> cl-end 0))
(let ((cl-p (if (> cl-start 0) (nthcdr cl-start cl-seq)
(setq cl-end (1- cl-end)) (cdr cl-seq))))
(while (and cl-p (> cl-end 0)
(not (cl-check-test cl-item (car cl-p))))
(not (cl--check-test cl-item (car cl-p))))
(setq cl-p (cdr cl-p) cl-end (1- cl-end)))
(if (and cl-p (> cl-end 0))
(nconc (cl-ldiff cl-seq cl-p)
@ -271,7 +263,7 @@ to avoid corrupting the original SEQ.
This is a destructive function; it reuses the storage of SEQ whenever possible.
\nKeywords supported: :test :test-not :key :count :start :end :from-end
\n(fn ITEM SEQ [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :if :if-not :count :from-end
(cl--parsing-keywords (:test :test-not :key :if :if-not :count :from-end
(:start 0) :end) ()
(if (<= (or cl-count (setq cl-count 8000000)) 0)
cl-seq
@ -291,7 +283,7 @@ This is a destructive function; it reuses the storage of SEQ whenever possible.
(progn
(while (and cl-seq
(> cl-end 0)
(cl-check-test cl-item (car cl-seq))
(cl--check-test cl-item (car cl-seq))
(setq cl-end (1- cl-end) cl-seq (cdr cl-seq))
(> (setq cl-count (1- cl-count)) 0)))
(setq cl-end (1- cl-end)))
@ -299,7 +291,7 @@ This is a destructive function; it reuses the storage of SEQ whenever possible.
(if (and (> cl-count 0) (> cl-end 0))
(let ((cl-p (nthcdr cl-start cl-seq)))
(while (and (cdr cl-p) (> cl-end 0))
(if (cl-check-test cl-item (car (cdr cl-p)))
(if (cl--check-test cl-item (car (cdr cl-p)))
(progn
(setcdr cl-p (cdr (cdr cl-p)))
(if (= (setq cl-count (1- cl-count)) 0)
@ -341,14 +333,14 @@ This is a destructive function; it reuses the storage of SEQ whenever possible.
(defun cl--delete-duplicates (cl-seq cl-keys cl-copy)
(if (listp cl-seq)
(cl-parsing-keywords (:test :test-not :key (:start 0) :end :from-end :if)
(cl--parsing-keywords (:test :test-not :key (:start 0) :end :from-end :if)
()
(if cl-from-end
(let ((cl-p (nthcdr cl-start cl-seq)) cl-i)
(setq cl-end (- (or cl-end (length cl-seq)) cl-start))
(while (> cl-end 1)
(setq cl-i 0)
(while (setq cl-i (cl--position (cl-check-key (car cl-p))
(while (setq cl-i (cl--position (cl--check-key (car cl-p))
(cdr cl-p) cl-i (1- cl-end)))
(if cl-copy (setq cl-seq (copy-sequence cl-seq)
cl-p (nthcdr cl-start cl-seq) cl-copy nil))
@ -360,13 +352,13 @@ This is a destructive function; it reuses the storage of SEQ whenever possible.
cl-seq)
(setq cl-end (- (or cl-end (length cl-seq)) cl-start))
(while (and (cdr cl-seq) (= cl-start 0) (> cl-end 1)
(cl--position (cl-check-key (car cl-seq))
(cl--position (cl--check-key (car cl-seq))
(cdr cl-seq) 0 (1- cl-end)))
(setq cl-seq (cdr cl-seq) cl-end (1- cl-end)))
(let ((cl-p (if (> cl-start 0) (nthcdr (1- cl-start) cl-seq)
(setq cl-end (1- cl-end) cl-start 1) cl-seq)))
(while (and (cdr (cdr cl-p)) (> cl-end 1))
(if (cl--position (cl-check-key (car (cdr cl-p)))
(if (cl--position (cl--check-key (car (cdr cl-p)))
(cdr (cdr cl-p)) 0 (1- cl-end))
(progn
(if cl-copy (setq cl-seq (copy-sequence cl-seq)
@ -386,7 +378,7 @@ This is a non-destructive function; it makes a copy of SEQ if necessary
to avoid corrupting the original SEQ.
\nKeywords supported: :test :test-not :key :count :start :end :from-end
\n(fn NEW OLD SEQ [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :if :if-not :count
(cl--parsing-keywords (:test :test-not :key :if :if-not :count
(:start 0) :end :from-end) ()
(if (or (eq cl-old cl-new)
(<= (or cl-count (setq cl-from-end nil cl-count 8000000)) 0))
@ -396,7 +388,7 @@ to avoid corrupting the original SEQ.
cl-seq
(setq cl-seq (copy-sequence cl-seq))
(or cl-from-end
(progn (cl-set-elt cl-seq cl-i cl-new)
(progn (cl--set-elt cl-seq cl-i cl-new)
(setq cl-i (1+ cl-i) cl-count (1- cl-count))))
(apply 'cl-nsubstitute cl-new cl-old cl-seq :count cl-count
:start cl-i cl-keys))))))
@ -425,14 +417,14 @@ to avoid corrupting the original SEQ.
This is a destructive function; it reuses the storage of SEQ whenever possible.
\nKeywords supported: :test :test-not :key :count :start :end :from-end
\n(fn NEW OLD SEQ [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :if :if-not :count
(cl--parsing-keywords (:test :test-not :key :if :if-not :count
(:start 0) :end :from-end) ()
(or (eq cl-old cl-new) (<= (or cl-count (setq cl-count 8000000)) 0)
(if (and (listp cl-seq) (or (not cl-from-end) (> cl-count 4000000)))
(let ((cl-p (nthcdr cl-start cl-seq)))
(setq cl-end (- (or cl-end 8000000) cl-start))
(while (and cl-p (> cl-end 0) (> cl-count 0))
(if (cl-check-test cl-old (car cl-p))
(if (cl--check-test cl-old (car cl-p))
(progn
(setcar cl-p cl-new)
(setq cl-count (1- cl-count))))
@ -441,12 +433,12 @@ This is a destructive function; it reuses the storage of SEQ whenever possible.
(if cl-from-end
(while (and (< cl-start cl-end) (> cl-count 0))
(setq cl-end (1- cl-end))
(if (cl-check-test cl-old (elt cl-seq cl-end))
(if (cl--check-test cl-old (elt cl-seq cl-end))
(progn
(cl-set-elt cl-seq cl-end cl-new)
(cl--set-elt cl-seq cl-end cl-new)
(setq cl-count (1- cl-count)))))
(while (and (< cl-start cl-end) (> cl-count 0))
(if (cl-check-test cl-old (aref cl-seq cl-start))
(if (cl--check-test cl-old (aref cl-seq cl-start))
(progn
(aset cl-seq cl-start cl-new)
(setq cl-count (1- cl-count))))
@ -500,7 +492,7 @@ Return the matching item, or nil if not found.
Return the index of the matching item, or nil if not found.
\nKeywords supported: :test :test-not :key :start :end :from-end
\n(fn ITEM SEQ [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :if :if-not
(cl--parsing-keywords (:test :test-not :key :if :if-not
(:start 0) :end :from-end) ()
(cl--position cl-item cl-seq cl-start cl-end cl-from-end)))
@ -510,7 +502,7 @@ Return the index of the matching item, or nil if not found.
(or cl-end (setq cl-end 8000000))
(let ((cl-res nil))
(while (and cl-p (< cl-start cl-end) (or (not cl-res) cl-from-end))
(if (cl-check-test cl-item (car cl-p))
(if (cl--check-test cl-item (car cl-p))
(setq cl-res cl-start))
(setq cl-p (cdr cl-p) cl-start (1+ cl-start)))
cl-res))
@ -518,10 +510,10 @@ Return the index of the matching item, or nil if not found.
(if cl-from-end
(progn
(while (and (>= (setq cl-end (1- cl-end)) cl-start)
(not (cl-check-test cl-item (aref cl-seq cl-end)))))
(not (cl--check-test cl-item (aref cl-seq cl-end)))))
(and (>= cl-end cl-start) cl-end))
(while (and (< cl-start cl-end)
(not (cl-check-test cl-item (aref cl-seq cl-start))))
(not (cl--check-test cl-item (aref cl-seq cl-start))))
(setq cl-start (1+ cl-start)))
(and (< cl-start cl-end) cl-start))))
@ -546,13 +538,13 @@ Return the index of the matching item, or nil if not found.
"Count the number of occurrences of ITEM in SEQ.
\nKeywords supported: :test :test-not :key :start :end
\n(fn ITEM SEQ [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :if :if-not (:start 0) :end) ()
(cl--parsing-keywords (:test :test-not :key :if :if-not (:start 0) :end) ()
(let ((cl-count 0) cl-x)
(or cl-end (setq cl-end (length cl-seq)))
(if (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
(while (< cl-start cl-end)
(setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start)))
(if (cl-check-test cl-item cl-x) (setq cl-count (1+ cl-count)))
(if (cl--check-test cl-item cl-x) (setq cl-count (1+ cl-count)))
(setq cl-start (1+ cl-start)))
cl-count)))
@ -577,14 +569,14 @@ Return nil if the sequences match. If one sequence is a prefix of the
other, the return value indicates the end of the shorter sequence.
\nKeywords supported: :test :test-not :key :start1 :end1 :start2 :end2 :from-end
\n(fn SEQ1 SEQ2 [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :from-end
(cl--parsing-keywords (:test :test-not :key :from-end
(:start1 0) :end1 (:start2 0) :end2) ()
(or cl-end1 (setq cl-end1 (length cl-seq1)))
(or cl-end2 (setq cl-end2 (length cl-seq2)))
(if cl-from-end
(progn
(while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2)
(cl-check-match (elt cl-seq1 (1- cl-end1))
(cl--check-match (elt cl-seq1 (1- cl-end1))
(elt cl-seq2 (1- cl-end2))))
(setq cl-end1 (1- cl-end1) cl-end2 (1- cl-end2)))
(and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2))
@ -592,7 +584,7 @@ other, the return value indicates the end of the shorter sequence.
(let ((cl-p1 (and (listp cl-seq1) (nthcdr cl-start1 cl-seq1)))
(cl-p2 (and (listp cl-seq2) (nthcdr cl-start2 cl-seq2))))
(while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2)
(cl-check-match (if cl-p1 (car cl-p1)
(cl--check-match (if cl-p1 (car cl-p1)
(aref cl-seq1 cl-start1))
(if cl-p2 (car cl-p2)
(aref cl-seq2 cl-start2))))
@ -608,14 +600,14 @@ Return the index of the leftmost element of the first match found;
return nil if there are no matches.
\nKeywords supported: :test :test-not :key :start1 :end1 :start2 :end2 :from-end
\n(fn SEQ1 SEQ2 [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :from-end
(cl--parsing-keywords (:test :test-not :key :from-end
(:start1 0) :end1 (:start2 0) :end2) ()
(or cl-end1 (setq cl-end1 (length cl-seq1)))
(or cl-end2 (setq cl-end2 (length cl-seq2)))
(if (>= cl-start1 cl-end1)
(if cl-from-end cl-end2 cl-start2)
(let* ((cl-len (- cl-end1 cl-start1))
(cl-first (cl-check-key (elt cl-seq1 cl-start1)))
(cl-first (cl--check-key (elt cl-seq1 cl-start1)))
(cl-if nil) cl-pos)
(setq cl-end2 (- cl-end2 (1- cl-len)))
(while (and (< cl-start2 cl-end2)
@ -636,7 +628,7 @@ This is a destructive function; it reuses the storage of SEQ if possible.
\n(fn SEQ PREDICATE [KEYWORD VALUE]...)"
(if (nlistp cl-seq)
(cl-replace cl-seq (apply 'cl-sort (append cl-seq nil) cl-pred cl-keys))
(cl-parsing-keywords (:key) ()
(cl--parsing-keywords (:key) ()
(if (memq cl-key '(nil identity))
(sort cl-seq cl-pred)
(sort cl-seq (function (lambda (cl-x cl-y)
@ -660,16 +652,15 @@ sequences, and PREDICATE is a `less-than' predicate on the elements.
\n(fn TYPE SEQ1 SEQ2 PREDICATE [KEYWORD VALUE]...)"
(or (listp cl-seq1) (setq cl-seq1 (append cl-seq1 nil)))
(or (listp cl-seq2) (setq cl-seq2 (append cl-seq2 nil)))
(cl-parsing-keywords (:key) ()
(cl--parsing-keywords (:key) ()
(let ((cl-res nil))
(while (and cl-seq1 cl-seq2)
(if (funcall cl-pred (cl-check-key (car cl-seq2))
(cl-check-key (car cl-seq1)))
(if (funcall cl-pred (cl--check-key (car cl-seq2))
(cl--check-key (car cl-seq1)))
(push (pop cl-seq2) cl-res)
(push (pop cl-seq1) cl-res)))
(cl-coerce (nconc (nreverse cl-res) cl-seq1 cl-seq2) cl-type))))
;;; See compiler macro in cl-macs.el
;;;###autoload
(defun cl-member (cl-item cl-list &rest cl-keys)
"Find the first occurrence of ITEM in LIST.
@ -678,8 +669,8 @@ Return the sublist of LIST whose car is ITEM.
\n(fn ITEM LIST [KEYWORD VALUE]...)"
(declare (compiler-macro cl--compiler-macro-member))
(if cl-keys
(cl-parsing-keywords (:test :test-not :key :if :if-not) ()
(while (and cl-list (not (cl-check-test cl-item (car cl-list))))
(cl--parsing-keywords (:test :test-not :key :if :if-not) ()
(while (and cl-list (not (cl--check-test cl-item (car cl-list))))
(setq cl-list (cdr cl-list)))
cl-list)
(if (and (numberp cl-item) (not (integerp cl-item)))
@ -705,12 +696,11 @@ Return the sublist of LIST whose car matches.
;;;###autoload
(defun cl--adjoin (cl-item cl-list &rest cl-keys)
(if (cl-parsing-keywords (:key) t
(apply 'cl-member (cl-check-key cl-item) cl-list cl-keys))
(if (cl--parsing-keywords (:key) t
(apply 'cl-member (cl--check-key cl-item) cl-list cl-keys))
cl-list
(cons cl-item cl-list)))
;;; See compiler macro in cl-macs.el
;;;###autoload
(defun cl-assoc (cl-item cl-alist &rest cl-keys)
"Find the first item whose car matches ITEM in LIST.
@ -718,10 +708,10 @@ Return the sublist of LIST whose car matches.
\n(fn ITEM LIST [KEYWORD VALUE]...)"
(declare (compiler-macro cl--compiler-macro-assoc))
(if cl-keys
(cl-parsing-keywords (:test :test-not :key :if :if-not) ()
(cl--parsing-keywords (:test :test-not :key :if :if-not) ()
(while (and cl-alist
(or (not (consp (car cl-alist)))
(not (cl-check-test cl-item (car (car cl-alist))))))
(not (cl--check-test cl-item (car (car cl-alist))))))
(setq cl-alist (cdr cl-alist)))
(and cl-alist (car cl-alist)))
(if (and (numberp cl-item) (not (integerp cl-item)))
@ -749,10 +739,10 @@ Return the sublist of LIST whose car matches.
\nKeywords supported: :test :test-not :key
\n(fn ITEM LIST [KEYWORD VALUE]...)"
(if (or cl-keys (numberp cl-item))
(cl-parsing-keywords (:test :test-not :key :if :if-not) ()
(cl--parsing-keywords (:test :test-not :key :if :if-not) ()
(while (and cl-alist
(or (not (consp (car cl-alist)))
(not (cl-check-test cl-item (cdr (car cl-alist))))))
(not (cl--check-test cl-item (cdr (car cl-alist))))))
(setq cl-alist (cdr cl-alist)))
(and cl-alist (car cl-alist)))
(rassq cl-item cl-alist)))
@ -813,13 +803,13 @@ to avoid corrupting the original LIST1 and LIST2.
\n(fn LIST1 LIST2 [KEYWORD VALUE]...)"
(and cl-list1 cl-list2
(if (equal cl-list1 cl-list2) cl-list1
(cl-parsing-keywords (:key) (:test :test-not)
(cl--parsing-keywords (:key) (:test :test-not)
(let ((cl-res nil))
(or (>= (length cl-list1) (length cl-list2))
(setq cl-list1 (prog1 cl-list2 (setq cl-list2 cl-list1))))
(while cl-list2
(if (if (or cl-keys (numberp (car cl-list2)))
(apply 'cl-member (cl-check-key (car cl-list2))
(apply 'cl-member (cl--check-key (car cl-list2))
cl-list1 cl-keys)
(memq (car cl-list2) cl-list1))
(push (car cl-list2) cl-res))
@ -845,11 +835,11 @@ to avoid corrupting the original LIST1 and LIST2.
\nKeywords supported: :test :test-not :key
\n(fn LIST1 LIST2 [KEYWORD VALUE]...)"
(if (or (null cl-list1) (null cl-list2)) cl-list1
(cl-parsing-keywords (:key) (:test :test-not)
(cl--parsing-keywords (:key) (:test :test-not)
(let ((cl-res nil))
(while cl-list1
(or (if (or cl-keys (numberp (car cl-list1)))
(apply 'cl-member (cl-check-key (car cl-list1))
(apply 'cl-member (cl--check-key (car cl-list1))
cl-list2 cl-keys)
(memq (car cl-list1) cl-list2))
(push (car cl-list1) cl-res))
@ -901,9 +891,9 @@ I.e., if every element of LIST1 also appears in LIST2.
\n(fn LIST1 LIST2 [KEYWORD VALUE]...)"
(cond ((null cl-list1) t) ((null cl-list2) nil)
((equal cl-list1 cl-list2) t)
(t (cl-parsing-keywords (:key) (:test :test-not)
(t (cl--parsing-keywords (:key) (:test :test-not)
(while (and cl-list1
(apply 'cl-member (cl-check-key (car cl-list1))
(apply 'cl-member (cl--check-key (car cl-list1))
cl-list2 cl-keys))
(pop cl-list1))
(null cl-list1)))))
@ -949,24 +939,26 @@ Any element of TREE which matches is changed to NEW (via a call to `setcar').
\n(fn NEW PREDICATE TREE [KEYWORD VALUE]...)"
(apply 'cl-nsublis (list (cons nil cl-new)) cl-tree :if-not cl-pred cl-keys))
(defvar cl--alist)
;;;###autoload
(defun cl-sublis (cl-alist cl-tree &rest cl-keys)
"Perform substitutions indicated by ALIST in TREE (non-destructively).
Return a copy of TREE with all matching elements replaced.
\nKeywords supported: :test :test-not :key
\n(fn ALIST TREE [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :if :if-not) ()
(cl-sublis-rec cl-tree)))
(cl--parsing-keywords (:test :test-not :key :if :if-not) ()
(let ((cl--alist cl-alist))
(cl--sublis-rec cl-tree))))
(defvar cl-alist)
(defun cl-sublis-rec (cl-tree) ; uses cl-alist/key/test*/if*
(let ((cl-temp (cl-check-key cl-tree)) (cl-p cl-alist))
(while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp)))
(defun cl--sublis-rec (cl-tree) ;Uses cl--alist cl-key/test*/if*.
(let ((cl-temp (cl--check-key cl-tree)) (cl-p cl--alist))
(while (and cl-p (not (cl--check-test-nokey (car (car cl-p)) cl-temp)))
(setq cl-p (cdr cl-p)))
(if cl-p (cdr (car cl-p))
(if (consp cl-tree)
(let ((cl-a (cl-sublis-rec (car cl-tree)))
(cl-d (cl-sublis-rec (cdr cl-tree))))
(let ((cl-a (cl--sublis-rec (car cl-tree)))
(cl-d (cl--sublis-rec (cdr cl-tree))))
(if (and (eq cl-a (car cl-tree)) (eq cl-d (cdr cl-tree)))
cl-tree
(cons cl-a cl-d)))
@ -978,20 +970,21 @@ Return a copy of TREE with all matching elements replaced.
Any matching element of TREE is changed via a call to `setcar'.
\nKeywords supported: :test :test-not :key
\n(fn ALIST TREE [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key :if :if-not) ()
(let ((cl-hold (list cl-tree)))
(cl-nsublis-rec cl-hold)
(cl--parsing-keywords (:test :test-not :key :if :if-not) ()
(let ((cl-hold (list cl-tree))
(cl--alist cl-alist))
(cl--nsublis-rec cl-hold)
(car cl-hold))))
(defun cl-nsublis-rec (cl-tree) ; uses cl-alist/temp/p/key/test*/if*
(defun cl--nsublis-rec (cl-tree) ;Uses cl--alist cl-key/test*/if*.
(while (consp cl-tree)
(let ((cl-temp (cl-check-key (car cl-tree))) (cl-p cl-alist))
(while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp)))
(let ((cl-temp (cl--check-key (car cl-tree))) (cl-p cl--alist))
(while (and cl-p (not (cl--check-test-nokey (car (car cl-p)) cl-temp)))
(setq cl-p (cdr cl-p)))
(if cl-p (setcar cl-tree (cdr (car cl-p)))
(if (consp (car cl-tree)) (cl-nsublis-rec (car cl-tree))))
(setq cl-temp (cl-check-key (cdr cl-tree)) cl-p cl-alist)
(while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp)))
(if (consp (car cl-tree)) (cl--nsublis-rec (car cl-tree))))
(setq cl-temp (cl--check-key (cdr cl-tree)) cl-p cl--alist)
(while (and cl-p (not (cl--check-test-nokey (car (car cl-p)) cl-temp)))
(setq cl-p (cdr cl-p)))
(if cl-p
(progn (setcdr cl-tree (cdr (car cl-p))) (setq cl-tree nil))
@ -1003,14 +996,14 @@ Any matching element of TREE is changed via a call to `setcar'.
Atoms are compared by `eql'; cons cells are compared recursively.
\nKeywords supported: :test :test-not :key
\n(fn TREE1 TREE2 [KEYWORD VALUE]...)"
(cl-parsing-keywords (:test :test-not :key) ()
(cl-tree-equal-rec cl-x cl-y)))
(cl--parsing-keywords (:test :test-not :key) ()
(cl--tree-equal-rec cl-x cl-y)))
(defun cl-tree-equal-rec (cl-x cl-y)
(defun cl--tree-equal-rec (cl-x cl-y) ;Uses cl-key/test*.
(while (and (consp cl-x) (consp cl-y)
(cl-tree-equal-rec (car cl-x) (car cl-y)))
(cl--tree-equal-rec (car cl-x) (car cl-y)))
(setq cl-x (cdr cl-x) cl-y (cdr cl-y)))
(and (not (consp cl-x)) (not (consp cl-y)) (cl-check-match cl-x cl-y)))
(and (not (consp cl-x)) (not (consp cl-y)) (cl--check-match cl-x cl-y)))
(run-hooks 'cl-seq-load-hook)