home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / 2097 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  3.4 KB

  1. Path: sparky!uunet!mcsun!uknet!edcastle!aiai!jeff
  2. From: jeff@aiai.ed.ac.uk (Jeff Dalton)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: creating LISP structures dynamically?
  5. Message-ID: <7011@skye.ed.ac.uk>
  6. Date: 24 Jul 92 19:39:03 GMT
  7. References: <1992Jun26.162734.13036@newshub.sdsu.edu> <12ft7kINNbb3@early-bird.think.com>
  8. Organization: AIAI, University of Edinburgh, Scotland
  9. Lines: 70
  10.  
  11. In article <12ft7kINNbb3@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
  12.  
  13. [Someone wants to create structures synamically in a planner/
  14. scheduler, but their specific question is about how to create
  15. _symbols_ dynamically.]
  16.  
  17. >MAKE-SYMBOL or INTERN, depending on whether you want the symbol to be
  18. >interned in a package or not.
  19.  
  20. Or even GENTEMP or (sometimes) GENSYM.
  21.  
  22. >However, going back to your original problem description, I'm not sure what
  23. >the purpose of these symbols is.  [...]
  24.  
  25. >  Your Subject line says that you want to create Lisp structures
  26. >dynamically, and that's what MAKE-MOVE (which I assume is a constructor
  27. >defined by DEFSTRUCT) does; but you somehow have gotten the notion that in
  28. >order to create structures dynamically you also need to create symbols
  29. >dynamically, but there's no such connection.
  30.  
  31. This puzzles me too.  I've seen it again and again in AI programs
  32. such as planners and schedulers, and from time to time I've asked
  33. the authors why they do it.  
  34.  
  35. Sometimes they think it's necessary to have an extra level of
  36. indirection, but whenever I've pressed them on it (so far), it's
  37. turned out that they aren't actually using the extra indirection
  38. in any interesting way.
  39.  
  40. Other people have thought that unless they attached each structure 
  41. to a symbol they would be getting _copies_ of the structures whenever
  42. they passed them as arguments in function calls.  (They plan to pass
  43. the symbols instead.)  That is, they are in the grip of a
  44. misunderstanding about how Lisp works.
  45.  
  46. But I don't think that's the whole story.  Apart from various
  47. confucions, there seem to a a couple of other factors at work:
  48.  
  49.   1. At one time, a common technique was to represent structures
  50.      as symbols with the plists holding the slots.  Because of
  51.      that, or for some other reason, the use of named objects
  52.      became conventional in certain areas of AI, and new programmers
  53.      learned this convention when they learned how to write AI
  54.      programs.
  55.  
  56.   2. Some people find it more natural to have named objects.
  57.      (Certainly some people find systems such as KEE that use
  58.      named objects more natural that, say, CLOS.)
  59.  
  60. In any case, I have never succeeded (so far) in getting anyone to stop
  61. using sybols or some other ids for structures.  The things that keep
  62. them from making the change seem to be:
  63.  
  64.   1. They want to be able to type in an id and get back the struct.
  65.  
  66.   2. They want complex and circular structures to print nicely.
  67.      For instance, if one struct contains (pointers to) others,
  68.      they want the others to print as simple ids rather than as
  69.      some complex contents in #s(...) notation.
  70.  
  71. My solution to these problems is to define :PRINT-FUNCTIONs that
  72. produce ids (as needed) that can be typed-in to get back the same
  73. struct.
  74.  
  75. However, because Common Lisp does not provide a way for a program to
  76. find all the slots of a struct (unless maybe the CLOS MOP now does
  77. it), defining a :PRINT-FUNCTION makes it difficult to get the #s(...)
  78. version in the cases where you still need it.
  79.  
  80. -- jd
  81.