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

* lisp/emacs-lisp/seq.el: Don't require cl-lib.

(seq-subseq): Move cl-subseq's code here instyead of calling it.
* lisp/emacs-lisp/cl-extra.el (cl-subseq): Use seq-subseq.
This commit is contained in:
Stefan Monnier 2019-10-27 13:25:00 -04:00
parent 2aaced1686
commit 0e4dd67aae
2 changed files with 23 additions and 22 deletions

View file

@ -57,7 +57,6 @@
;;; Code:
(eval-when-compile (require 'cl-generic))
(require 'cl-lib) ;; for cl-subseq
(defmacro seq-doseq (spec &rest body)
"Loop over a sequence.
@ -151,7 +150,27 @@ If END is omitted, it defaults to the length of the sequence. If
START or END is negative, it counts from the end. Signal an
error if START or END are outside of the sequence (i.e too large
if positive or too small if negative)."
(cl-subseq sequence start end))
(cond
((or (stringp sequence) (vectorp sequence)) (substring sequence start end))
((listp sequence)
(let (len
(errtext (format "Bad bounding indices: %s, %s" start end)))
(and end (< end 0) (setq end (+ end (setq len (length sequence)))))
(if (< start 0) (setq start (+ start (or len (setq len (length sequence))))))
(unless (>= start 0)
(error "%s" errtext))
(when (> start 0)
(setq sequence (nthcdr (1- start) sequence))
(or sequence (error "%s" errtext))
(setq sequence (cdr sequence)))
(if end
(let ((res nil))
(while (and (>= (setq end (1- end)) start) sequence)
(push (pop sequence) res))
(or (= (1+ end) start) (error "%s" errtext))
(nreverse res))
(copy-sequence sequence))))
(t (error "Unsupported sequence: %s" sequence))))
(cl-defgeneric seq-map (function sequence)