Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!bbn!bbn.com!mesard From: mesard@bbn.com (Wayne Mesard) Newsgroups: comp.lang.lisp Subject: Re: Creating an array of structures Keywords: Defstruct, Make-array Message-ID: <47160@bbn.COM> Date: 20 Oct 89 00:52:35 GMT References: <5244@lindy.Stanford.EDU> Sender: news@bbn.COM Reply-To: mesard@BBN.COM (Wayne Mesard) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 25 giant@lindy.Stanford.EDU (Buc Richards) writes: >When I make an array of structures, any changes to any of the elements >change all the elements. What am I dong wrong? [...] > (Setf tc (Make-array 25 :Element-type 'cardtype > :Initial-element (make-cardtype))) MAKE-CARDTYPE gets called once and only once. Every element in the array then contains a pointer to the ONE structure which was created. Changing one changes them all because they are one and the same. :INITIAL-ELEMENT probably isn't what you want. Try :INITIAL-CONTENTS. E.g.: (Setf tc (Make-array 25 :Element-type 'cardtype :Initial-contents (do ((i 25 (1- i)) (lis nil (cons (make-cardtype) lis))) ((zerop i) lis)))) Disclaimer: The DO may or may not be the politically correct way to cons up the list. Wayne();