Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!gatech!udel!princeton!phoenix!eliot From: eliot@phoenix.Princeton.EDU (Eliot Handelman) Newsgroups: comp.lang.lisp Subject: Re: Partially displaced arrays? Message-ID: <9621@phoenix.Princeton.EDU> Date: 27 Jul 89 00:40:56 GMT References: <9562@phoenix.Princeton.EDU> <25364@news.Think.COM> Reply-To: eliot@phoenix.Princeton.EDU (Eliot Handelman) Organization: Princeton University, NJ Lines: 35 In article <25364@news.Think.COM> barmar@kulla.UUCP (Barry Margolin) writes: >In article <9562@phoenix.Princeton.EDU> eliot@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.