diff options
| author | Colin Walters | 2002-06-08 20:48:15 +0000 |
|---|---|---|
| committer | Colin Walters | 2002-06-08 20:48:15 +0000 |
| commit | a176c9ebfbd7bfb36342de647e5f056588fd5b82 (patch) | |
| tree | 601f76b5e344499860d41fa3dec7c507345a5e71 | |
| parent | 506a6d7e1b11796ab8f6666a990fb3c377e35cc5 (diff) | |
| download | emacs-a176c9ebfbd7bfb36342de647e5f056588fd5b82.tar.gz emacs-a176c9ebfbd7bfb36342de647e5f056588fd5b82.zip | |
(copy-list): Moved here from cl.el.
(copy-tree): Renamed here from `cl-copy-tree' in cl.el.
| -rw-r--r-- | lisp/subr.el | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index e6b0ca945a4..7b613b42e63 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -191,6 +191,33 @@ The comparison is done with `eq'." | |||
| 191 | (delq elt (copy-sequence list)) | 191 | (delq elt (copy-sequence list)) |
| 192 | list)) | 192 | list)) |
| 193 | 193 | ||
| 194 | (defun copy-list (list) | ||
| 195 | "Return a copy of a list, which may be a dotted list. | ||
| 196 | The elements of the list are not copied, just the list structure itself." | ||
| 197 | (if (consp list) | ||
| 198 | (let ((res nil)) | ||
| 199 | (while (consp list) (push (pop list) res)) | ||
| 200 | (prog1 (nreverse res) (setcdr res list))) | ||
| 201 | (car list))) | ||
| 202 | |||
| 203 | (defun copy-tree (tree &optional vecp) | ||
| 204 | "Make a copy of TREE. | ||
| 205 | If TREE is a cons cell, this recursively copies both its car and its cdr. | ||
| 206 | Contrast to copy-sequence, which copies only along the cdrs. With second | ||
| 207 | argument VECP, this copies vectors as well as conses." | ||
| 208 | (if (consp tree) | ||
| 209 | (let ((p (setq tree (copy-list tree)))) | ||
| 210 | (while (consp p) | ||
| 211 | (if (or (consp (car p)) (and vecp (vectorp (car p)))) | ||
| 212 | (setcar p (copy-tree (car p) vecp))) | ||
| 213 | (or (listp (cdr p)) (setcdr p (copy-tree (cdr p) vecp))) | ||
| 214 | (cl-pop p))) | ||
| 215 | (if (and vecp (vectorp tree)) | ||
| 216 | (let ((i (length (setq tree (copy-sequence tree))))) | ||
| 217 | (while (>= (setq i (1- i)) 0) | ||
| 218 | (aset tree i (copy-tree (aref tree i) vecp)))))) | ||
| 219 | tree) | ||
| 220 | |||
| 194 | (defun assoc-default (key alist &optional test default) | 221 | (defun assoc-default (key alist &optional test default) |
| 195 | "Find object KEY in a pseudo-alist ALIST. | 222 | "Find object KEY in a pseudo-alist ALIST. |
| 196 | ALIST is a list of conses or objects. Each element (or the element's car, | 223 | ALIST is a list of conses or objects. Each element (or the element's car, |