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

  1. Path: sparky!uunet!mcsun!uknet!ox-prg!gordon
  2. From: gordon@robots.oxford.ac.uk (Gordon Buxton)
  3. Newsgroups: comp.lang.lisp
  4. Subject: local macro definitions
  5. Message-ID: <4133@inca.comlab.ox.ac.uk>
  6. Date: 27 Jul 92 14:52:29 GMT
  7. Sender: news@comlab.ox.ac.uk
  8. Distribution: comp.lang.lisp
  9. Organization: Robotics Research Group, Engineering Science Dept, Oxford, UK.
  10. Lines: 60
  11.  
  12. Sorry if this is a naive question, but you all seem pretty
  13. knowledgeable:
  14.  
  15. I'm trying to write a function for accessing data stored in slots of
  16. frames.  The problem is that if no value is available from that slot,
  17. I want to go and execute a bit of user code attached to that slot.
  18. The basic function that I am using looks like this:
  19.  
  20. (val '<frame-name> '<slot-name>)
  21.  
  22. At the moment, the user code attached to the slot gets called with the
  23. symbol 'self' bound to the value of <frame-name>.  This lets the user
  24. code get at values from other slots in the same frame by inserting
  25.  
  26. ... (val self '<another-slot-name>) ...
  27.  
  28. as part of the code.  This is pretty horrible.  What I would really
  29. like to do is to let the user refer to the other slot names in the
  30. frame as if they were locally bound variables: eg. you could do:
  31.  
  32. (+ <slot-1> <slot-2>)
  33.  
  34. as a valid part of the code.
  35.  
  36. Does anyone have any great ideas on doing this?  The following methods
  37. I have thought of, but are either no good or I don't know how to
  38. implement them:
  39.  
  40. 1. A list of all of the slots present in a frame is available; the
  41. user code calling sequence could bind each slot name to the value of
  42. the (val ..) function called for that slot.
  43.  
  44.     -- Inefficient to say the least.  In fact it gets more hideous
  45.        the more you think about it.
  46.  
  47. 2. Do some parsing on the user code, to work out which slots are
  48. needed, and just go and get them before executing the code.
  49.  
  50.     -- Doesn't strike me as a good idea.
  51.  
  52. 3. Bind each of the slot names to a macro (macrolet ... ?) that then
  53. gets expanded to (val self '<slot-name>) upon execution.
  54.  
  55. -- This is the one I like best, but there are two problems:
  56.    a) The user-code function call is already constructed using the
  57.       backquote - I'd have to expand macros within this.
  58.    b) I don't know how to do it, or if it is possible
  59.  
  60. Your help would be greatly appreciated on this.
  61.  
  62. Thanks
  63.  
  64. Gordon
  65.  
  66. --------------------------
  67. gordon@robots.oxford.ac.uk
  68. Gordon Buxton
  69. Pembroke College
  70. Oxford OX1 1DW
  71. --------------------------
  72.