Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!ssc-vax!bcsaic!lbaum From: lbaum@bcsaic.UUCP (Larry Baum) Newsgroups: comp.lang.lisp Subject: Re: query 'bout defstruct (Common LISP) Message-ID: <5190@bcsaic.UUCP> Date: 3 May 88 20:59:20 GMT References: <10834@cgl.ucsf.EDU> Reply-To: lbaum@bcsaic.UUCP (Larry Baum) Organization: Boeing Computer Services AI Center, Seattle Lines: 28 Keywords: defstruct, symbols, confusion In article <10834@cgl.ucsf.EDU> yee@cgl.ucsf.edu (dave yee) writes: >i would like to define a data structure using defstruct. > >... Now for the tricky part. I will have a variable >number of "pieces" at any given time in the program. >So i would like the computer to >generate new symbols for me. The new symbols would then >be used as names for the new pieces. > >Now, i figured i could use "gentemp" to make the symbols, >but i can't "setq" these new symbols (i.e. >(setq (gentemp) (make-piece)) just doesn't cut it... > You could do: (set (gentemp) (make-piece)) However, while this will successfully do the binding, it will defeat your goal of having a name for your object, since the symbol returned by (gentemp) has been lost. Better would be: (let ((symb (gentemp))) (set symb (make-piece)) ... code to get a handle on symb ...) If you are going to have many, many pieces, then storing them in a hash table will probably give to better performance. LSB