Path: utzoo!attcan!uunet!husc6!bbn!mit-eddie!ll-xn!ames!nrl-cmf!cmcl2!phri!manhat!mancol!jh From: jh@mancol.UUCP (John Hanley) Newsgroups: comp.lang.lisp Subject: Re: query 'bout defstruct (Common LISP) Keywords: defstruct, symbols, confusion Message-ID: <384@mancol.UUCP> Date: 13 May 88 20:43:41 GMT References: <10834@cgl.ucsf.EDU> <5190@bcsaic.UUCP> <28800@yale-celray.yale.UUCP> <974@umbc3.UMD.EDU> Reply-To: jh@manhat.UUCP (John Hanley) Organization: Manhattan College Lines: 85 >The motivation behind the gensyms is to avoid a list or table structure. I submit that you probably don't have a clear enough idea of what you want your data structure to look like if you're using arguments like this. Picking an appropriate data structure is crucial to coming up with a good algorithm, and can structure the way you view the problem. It's worth investing the time in doing some serious thinking about your data structure, and examining and discarding alternatives. >Symbols have the advantage of not having an explicit value when they are generated Is 'this-is-not-a-value a bad value to give to a brand new table entry? >The symbol tags also mean that I don't have to jerk around with a table >lookup, in that I can use the existing interface (ie: the obstack). In Vax Lisp, symbol->value lookups are done with a big hashtable, named 'user (or whatever your favorite package name is). I don't know about other Common Lisps, but I assume that as long as they go to the trouble of implementing generic hash tables, they might as well use them for symbol lookups. Y'all are familiar with (gethash), right? If not, you are strongly urged to look it up in Guy Steele's "Common Lisp: the language" or to at least type (describe 'gethash). Hash tables are great: the functionality of assoc lists (well, OK, so you can't go backwards) plus the efficiency of hashing, and you never have to worry about performance while you're just testing because tables automatically grow to accomodate more items. > Symbols can have plists. Ugh! Now you really don't know what you're doing! Plists are to data structures as goto's are to control structures. 1/2-) Seriously, they have their uses sometimes, but there's no reason the same information couldn't be stored as a table (so now we have a table of values, and each value is itself a table). I don't see anything special about symbols that makes them inherently more powerful than a-lists or hashtables. If you like symbols, fine, use them. I kind of like the ability to print out my table at any time and see the _entire_ data structure so I can see if things are as they should be. --John Hanley System Programmer, Manhattan College ..!cmcl2.nyu.edu!manhat!jh or hanley@nyu.edu (CMCL2<=>NYU.EDU) In case the original article expired on your system, here's the discussion I was adding to: In article <974@umbc3.UMD.EDU> alex@umbc3.UMD.EDU (Alex S. Crain) writes: >In article <28800@yale-celray.yale.UUCP> krulwich-bruce@CS.YALE.EDU (Bruce Krulwich) writes: >>In article <10834@cgl.ucsf.EDU> yee@cgl.ucsf.edu (dave yee) writes: >>>... 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. >> >>I have to ask: Why would you ever want to do this?? If you're going >>to have a variable number of pieces then you'll want to store them in >>a list or table anyway. Why bother GENing symbols?? > > I did not post the original request, but I have this identical problem >for a project that I'm doing now. The motivation behind the gensyms is to >avoid a list or table structure. My project is projecting a dynamic knowege >base over a neural net built on interrelated symbols. Symbols have the >advantage of not having an explicit value when they are generated, so I can >bind an undefined object, and define it's value later. > > The symbol tags also mean that I don't have to jerk around with a table >lookup, in that I can use the existing interface (ie: the obstack). > > Using symbols over list elements or table indexes makes tracing >through the resulting data structure a piece of cake. > > Symbols can have plists. > > > I welcome rebuttles to any of these motives.... > >-- > :alex. > >nerwin!alex@umbc3.umd.edu >alex@umbc3.umd.edu