copying vectors/arrays by value 
Author Message
 copying vectors/arrays by value

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



Sat, 20 Jan 2001 03:00:00 GMT  
 copying vectors/arrays by value

....

Quote:
>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

                                Commander Nathan Spring, "Starcops"



Sat, 20 Jan 2001 03:00:00 GMT  
 copying vectors/arrays by value

Quote:
>   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.



Sat, 20 Jan 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Copying one array value into subsequent array values

2. no vector = vector*vector in BLAS?

3. Problem with arrays of arrays (matrices) copying

4. Distributions and integrals, and old copies of VECTOR

5. Index Values of an Array inside a Cluster inside an Array

6. changing array values with the same array

7. lack of vector-copy in r4rs

8. copying a vector?

9. Problem with vector copy

10. java array return value not array in tcl

11. Constructing SFRotation values from positional vector

12. How to model unknown values in a vector?

 

 
Powered by phpBB® Forum Software