From: Barry Margolin
Subject: Re: Displacing a 1xn -> 4xm [m<n] array?
Date: 
Message-ID: <21ksgeINNc3k@early-bird.think.com>
In article <·····················@waikato.ac.nz> ···@waikato.ac.nz writes:
>Can anyone suggest a method of converting a 1-d (1xn) double-float array to a
>4xm [m < n] double-float array - using either (make-array :displace-to) or
>(adjust-array <1-d> <?>), or a combination  of the two?

>Note: What ever gets inserted/changed in the first row of the 4xm array *must*
> alter the first m elements in the 1xn array.

You can't do it with ADJUST-ARRAY, since that requires the old and new
dimensions to be the same rank (some implementations may relax this
restriction, but code that uses it won't be portable).

But displacing works fine:

(defun make-4-row-array (vector)
  (make-array (list 4
		    (/ (array-dimension vector 0) 4))
	      :element-type (array-element-type vector)
	      :displaced-to vector))

Command: (setq foo (vector 0 1 2 3 4 5 6 7 8 9 10 11))
#(0 1 2 3 4 5 6 7 8 9 10 11)
Command: (setq bar (make-4-row-array foo))
#2A((0 1 2) (3 4 5) (6 7 8) (9 10 11))
Command: (setf (aref bar 0 1) 100)
100
Command: bar
#2A((0 100 2) (3 4 5) (6 7 8) (9 10 11))
Command: foo
#(0 100 2 3 4 5 6 7 8 9 10 11)
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar