Initializing lists/arrays with structures
From: Andreas Yankopolus (andreas_at_nospam.yank.to)
Date: 02/27/04
- Next message: Tim Bradshaw: "Re: Popularity of programming languages"
- Previous message: Duane Rettig: "Re: Garbage Collection and Foreign Data"
- Next in thread: Peter Seibel: "Re: Initializing lists/arrays with structures"
- Reply: Peter Seibel: "Re: Initializing lists/arrays with structures"
- Reply: Tim Bradshaw: "Re: Initializing lists/arrays with structures"
- Reply: Wolfhard Buß: "Re: Initializing lists/arrays with structures"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Tim Bradshaw: "Re: Popularity of programming languages"
- Previous message: Duane Rettig: "Re: Garbage Collection and Foreign Data"
- Next in thread: Peter Seibel: "Re: Initializing lists/arrays with structures"
- Reply: Peter Seibel: "Re: Initializing lists/arrays with structures"
- Reply: Tim Bradshaw: "Re: Initializing lists/arrays with structures"
- Reply: Wolfhard Buß: "Re: Initializing lists/arrays with structures"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|