Re: copying arrays



On Apr 29, 11:16 am, Q <qal...@xxxxxxxxx> wrote:
Hi all,

Simple question:

CL-USER 37 > (setf a (make-array 5 :initial-element 7))
#(7 7 7 7 7)

CL-USER 38 > (setf b a)
#(7 7 7 7 7)

CL-USER 39 > (eq a b)
T

CL-USER 40 > (setf (aref a 0) 9)
9

CL-USER 41 > a
#(9 7 7 7 7)

CL-USER 42 > b
#(9 7 7 7 7)

How do I pass copies of the array around, instead of the array
itself? I don't want them to be eq. But, it'd be nice if they were
equal :)
And then there's the problem - what if the array contains instances of
other arrays (or lists, or hashtables, or what not for that matter)?
Do you want to copy the member arrays? Or use the member array
directly? What if we have two arrays that happen to contain each
other?

In my experience it's quite rare to have to have to *copy* a
sequence. If you're manipulating an array, why would you want to
retain the previous version? What is it that you are trying to do?
In general, it is usually very rare that you have to actually copy the
sequence.

.



Relevant Pages

  • Re: top-n/bottom-n?
    ... pointers on existing implementations as a starting point: Given a list (or array), I'd like to get a list of the top or bottom N elements which would be returned either as the elements themselves or as indexes to the elements in the list passed. ... that maps directly to inputed sequence. ... case is writing the top-n for lists. ... CL-USER 4> vsub ...
    (comp.lang.lisp)
  • Re: Efficiency of arrays in LISP
    ... I am wondering the array functions ... % CL-USER> ... I am not sure I like the double (aref vec ...) for each element, ...
    (comp.lang.lisp)
  • Re: newbie looping question
    ... So one might write routines to map between lists ... CL-USER> ... Then you can make an array ... and access elements by applying aref to the list of indices ...
    (comp.lang.lisp)
  • Re: copying arrays
    ... CL-USER 38> ... How do I pass copies of the array around, ... "Algebra is the metaphysics of arithmetic." ... "As long as algebra is taught in school, ...
    (comp.lang.lisp)
  • Re: The code of co-workers
    ... -all of the pointers have to be valid (dereferencing an invalid pointer ... -*i+1 and *j+1 must be valid indices into the array that a points into ... these are modified between the same pair of sequence points (modifying ... To avoid burying any useful diagnostics in useless ones, ...
    (comp.programming)