From: Marc LeBrun

Subject: Re: Feedback (copy-array)

Date: 2002-5-3 11:41

That should work fine, but of course as a matter of style it's better not 
to needlessly put the intermediate results in named variables (that just 
made it clearer what's going on).

If you copy arrays a lot you might want to define a function like this 
which will work with any shape array

(defun copy-array (array)
   (make-array
     (array-dimensions array)
     :displaced-to
       (copy-seq
         (make-array
           (array-total-size array)
           :displaced-to array))))

(or something like that--sorry for any typos, I don't have time to run this...)

Actually, it can get quite a bit more elaborate.  You can add stuff to 
duplicate the element-type, fill-pointer (if there is one) etc, either for 
performance or completeness.

You might also want to carefully review your current spec for 
adjust-array.  My 2nd edition of CLtL has some interesting comments 
(p458).  One is that the implementation is not supposed to collapse the 
chain of displacements, so the above approach will incur some overhead for 
the indirections.  On the other hand it also says that adjusting an array 
from displaced to non-displaced requires the implementation to copy the 
data.  Therefore it would seem the following code might be somewhat more 
efficient (assuming you care) both by reducing the indirection and because 
the copying will get done internally in adjust-array, rather than having to 
pass though the interface to copy-seq (with argument processing, type 
checking etc overhead).

(defun copy-array (array)
   (let ((dims (array-dimensions array)))
     (adjust-array
       (make-array dims :displaced-to array)
       dims)))

"Enjoy"!