Subject: Re: adjust-array vs. :adjustable t
From: (Rob Warnock)
Date: Wed, 06 Sep 2006 03:57:31 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Pascal Bourguignon  <> wrote:
| Ivan Boldyrev <> 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!!")

    > (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))
	    (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.


p.s. We should also remind OP that only vectors can have fill pointers...

Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607