Pascal Bourguignon <pjb@informatimago.com> wrote:
+---------------
| Ivan Boldyrev <boldyrev+nospam@cgitftp.uiggm.nsc.ru> writes:
| > (make-array (array-dimensions original-array)
| > :initial-contents original-array
| > :fill-pointer t
| > :adjustable t)
|
| Initial contents must be a list of lists.
+---------------
Uh, no, initial contents must be "a nested structure of sequences"
[CLHS Function MAKE-ARRAY]. His code works just fine on vectors
(well, he forgot to copy the element type):
> (deflex original-array "hello there, world!!")
ORIGINAL-ARRAY
> (make-array (array-dimensions original-array)
:initial-contents original-array
:element-type (array-element-type original-array)
:fill-pointer t
:adjustable t)
"hello there, world!!"
cmu> (describe *)
"hello there, world!" is a vector of length 20.
It has a fill pointer, currently 20
Its element type is specialized to BASE-CHAR.
>
And for multi-dimensional arrays [rank >1], one can use the double
:DISPLACED-TO trick that Barry Margolin posted week before last,
tweaked so the final array is adjustable:
;;; caveat: only lightly tested
(let* ((tmp-vector1
(make-array (array-total-size original-array)
:element-type (array-element-type original-array)
:displaced-to original-array))
(tmp-vector2
(make-array (array-total-size original-array)
:element-type (array-element-type original-array)
:adjustable t
:initial-contents tmp-vector1)))
(make-array (array-dimensions original-array)
:element-type (array-element-type original-array)
:adjustable t
:displaced-to tmp-vector2))
In neither case is an explicit copy needed, nor conversion of the
contents to lists.
-Rob
p.s. We should also remind OP that only vectors can have fill pointers...
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607