From: Eliot Handelman
Subject: Partially displaced arrays?
Date: 
Message-ID: <9562@phoenix.Princeton.EDU>
Thanks to some fool representation that I've been using, I need to
create arrays that are partially displaced to other arrays.

Supposing this is the array:

	   -----------------
           |   | X | X | X |
	   -----------------
           |   |   |   |   |
	   -----------------

I need to create a second array that shares only those locations marked
X, so that changes in those slots are reflected in the "displaced" array.
Does this at all seem possible? (I don't think so, and I'm about to start
rewriting code.)

Thanks for any advice!

From: Barry Margolin
Subject: Re: Partially displaced arrays?
Date: 
Message-ID: <25364@news.Think.COM>
In article <····@phoenix.Princeton.EDU> ·····@phoenix.Princeton.EDU (Eliot Handelman) writes:
>Supposing this is the array:
>	   -----------------
>           |   | X | X | X |
>	   -----------------
>           |   |   |   |   |
>	   -----------------
>I need to create a second array that shares only those locations marked
>X, so that changes in those slots are reflected in the "displaced" array.

Common Lisp requires that arrays be stored in row-major format.
Therefore, assuming your diagram is consistent with that
representation, the following should work:

(setq array-2 (make-array 3 :displaced-to array-1
			    :displaced-index-offset 1))

This specifies that the displaced array should only be three elements
long and should start at the second element of the original array.
Elements 0, 1, and 2 of the displaced array will correspond to
elements (0, 1), (0, 2), and (0, 3) of the target array.

Barry Margolin
Thinking Machines Corp.

······@think.com
{uunet,harvard}!think!barmar
From: Eliot Handelman
Subject: Re: Partially displaced arrays?
Date: 
Message-ID: <9621@phoenix.Princeton.EDU>
In article <·····@news.Think.COM> ······@kulla.UUCP (Barry Margolin) writes:
>In article <····@phoenix.Princeton.EDU> ·····@phoenix.Princeton.EDU (Eliot Handelman) writes:
>>Supposing this is the array:
>>	   -----------------
>>           |   | X | X | X |
>>	   -----------------
>>           |   |   |   |   |
>>	   -----------------
>>I need to create a second array that shares only those locations marked
>>X, so that changes in those slots are reflected in the "displaced" array.

>Common Lisp requires that arrays be stored in row-major format.
>Therefore, assuming your diagram is consistent with that
>representation, the following should work:

>(setq array-2 (make-array 3 :displaced-to array-1
>			    :displaced-index-offset 1))


Well, a bit of a misunderstanding here, for which I'm no doubt at fault.
My point was that the second array is the same dimensions as the first, but
only shares specified slots.

An interesting suggestion was to make the shared elements of arrays cons
cells, and use CAR & RPLACD to access and update the elements, something
like this:

(setq array-1 (make-array 2 :initial-contents (list (cons nil nil)
						    (cons nil nil))))

(setq array-2 (make-array 2 :initial-contents (list (aref array-1 0)
						    (cons nil nil))))

So now both arrays share [0], but not [1], and an arbitrary configuration
of slots can be shared between an arbitrary number of arrays.