Hi,
I just tried to copy a vector with both copy-seq and copy-tree. The
problem is that although it's a new vector, the elements are still
pointing to the parent. there's no such thing as `copy-array' as far
as I know, so I just used `concatenate'. But what I want to know is,
if my array had more dimensions, and I wanted a really deep copy
(recursive, and nothing pointing back to the original), then what
would I use? Is there a copy primitive for arrays?
dave
In article <···············@engc.bu.edu>, David Bakhash <·····@bu.edu> wrote:
....
>if my array had more dimensions, and I wanted a really deep copy
>(recursive, and nothing pointing back to the original), then what
>would I use? Is there a copy primitive for arrays?
Unlike "equality" where there are EQ,EQUAL,EQUALP which folks periodically
want to "extend"... there is no "default" copy for arrays (that I know of).
The question of "a deep copy" seems to be in the same ballpark as
the question of "equality". It is likely that for your own use of a
"deep" data structure you will need you own "equality" predicate and
"deep" duplicator.
--
Lyman S. Taylor "Computers are too reliable to replace
(·····@cc.gatech.edu) humans effectively."
Commander Nathan Spring, "Starcops"
·····@cc.gatech.edu (Lyman S. Taylor) writes:
> The question of "a deep copy" seems to be in the same ballpark as
> the question of "equality". It is likely that for your own use of a
> "deep" data structure you will need you own "equality" predicate and
> "deep" duplicator.
Yes, but lest a confusion arise--a multi-dimensional array in Lisp is
not an array of arrays, so if the question about deep copying was just
about copying "all axes", that is a non-issue in Lisp.
One can copy a multi-d array by something like:
(defun copy-array (old)
(let* ((fill-pointer (when (array-has-fill-pointer-p old)
(fill-pointer old)))
(new (make-array (array-dimensions old)
:fill-pointer fill-pointer
:element-type (array-element-type old))))
(dotimes (i (or fill-pointer (array-total-size old)))
(setf (row-major-aref new i) (row-major-aref old i)))
new))
--Kent (still on vacation, so still not bothering to test his
code examples even as flimsily as he might otherwise)
p.s. My Lisp Pointers paper
http://world.std.com/~pitman/PS/EQUAL.html
addresses the equal/copy issue in some detail. If you're one of the
few people who hasn't been badgered into looking at it already,
this might be a good time to check it out.