Re: How to make a copy of a list



På Wed, 30 Apr 2008 00:59:58 +0200, skrev Kaz Kylheku <kkylheku@xxxxxxxxx>:


Now we can add multi-dimensional array support. CLOS should match on
VECTOR more specifically if the array is one dimensional, and pass the
greater than rank 2 ones to this specialization:

(defmethod deep-copy ((array array))
;; exercise for reader
)


Good point! But using row-major-aref rather than aref should work for multi-dimentional array's too.
You would need to use array-total-size too.
Or a displacement array.

untested.

(loop for index from 0 below (array-total-size sequence)
do (setf (row-major-aref sequence index) (deep-copy (row-major-aref sequence index)

or

(loop for element across (make-array (array-total-size sequence) :displaced-to sequence)
do (setf element (deep-copy element)))

--------------
John Thingstad
.