source: trunk/j/src/org/armedbear/lisp/copy-seq.lisp @ 4251

Last change on this file since 4251 was 4251, checked in by piso, 19 years ago

Refactoring.

File size: 1.5 KB
Line 
1;;; copy-seq.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: copy-seq.lisp,v 1.3 2003-10-08 13:52:22 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(in-package "SYSTEM")
21
22;; From CMUCL.
23
24(defmacro vector-copy-seq (sequence type)
25  `(let ((length (length ,sequence)))
26     (do ((index 0 (1+ index))
27    (copy (make-sequence-of-type ,type length)))
28       ((= index length) copy)
29       (setf (aref copy index) (aref ,sequence index)))))
30
31(defmacro list-copy-seq (list)
32  `(if (atom ,list) '()
33       (let ((result (cons (car ,list) '()) ))
34   (do ((x (cdr ,list) (cdr x))
35        (splice result
36          (cdr (rplacd splice (cons (car x) '() ))) ))
37           ((atom x) (unless (null x)
38                       (rplacd splice x))
39            result)))))
40
41(defun copy-seq (sequence)
42  (if (listp sequence)
43      (list-copy-seq sequence)
44      (vector-copy-seq sequence (type-of sequence))))
Note: See TracBrowser for help on using the repository browser.