Initializing lists/arrays with structures

From: Andreas Yankopolus (andreas_at_nospam.yank.to)
Date: 02/27/04


Date: Fri, 27 Feb 2004 10:31:09 -0600

Is there a standard way to initialize a list or array with multiple
instances of a structure? In the following naive example, each element
of the list points to the same instance of element:

[72]> (defstruct element (x 0) (y 0))
ELEMENT
[73]> (setf foo (make-list 3 :initial-element (make-element)))
(#S(ELEMENT :X 0 :Y 0) #S(ELEMENT :X 0 :Y 0) #S(ELEMENT :X 0 :Y 0))
[74]> (setf (element-x (car foo)) 1)
1
[75]> foo
(#S(ELEMENT :X 1 :Y 0) #S(ELEMENT :X 1 :Y 0) #S(ELEMENT :X 1 :Y 0))

I've run into similar problems with make-array, since :initial-contents
want a list.

Thanks,

Andreas



Relevant Pages

  • Re: Initializing lists/arrays with structures
    ... > Is there a standard way to initialize a list or array with multiple ...
    (comp.lang.lisp)
  • Re: Writing hexadecimal to file
    ... Current limitations are that your array must have a ... multiple of 4 bits in it - which yours does. ... std_logic_textio is not a standard yet. ...
    (comp.lang.vhdl)
  • Re: initializing array using pointer
    ... >>suppose i have a pointer to an array of integers.can i initialize each ... the standard itself uses the word in this informal sense (I don't ...
    (comp.lang.c)
  • Bug+fix: PDC20271 RAID detection fails
    ... My array was not detected by my kernel. ... the PDC RAID superblock, that is located at the start ... of the last track on the disk. ... is a multiple of track size and if not, ...
    (comp.os.linux.hardware)
  • Re: Why C Is Not My Favourite Programming Language
    ... And the number of modules in Python 2.4's Global Module Index is 362. ... The PDP architecture ideals ... fflushcan't be used to flush the contents of standard ... But it's not foolish that in ksh if you refer to an array name ...
    (comp.lang.c)