home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!ox-prg!gordon
- From: gordon@robots.oxford.ac.uk (Gordon Buxton)
- Newsgroups: comp.lang.lisp
- Subject: local macro definitions
- Message-ID: <4133@inca.comlab.ox.ac.uk>
- Date: 27 Jul 92 14:52:29 GMT
- Sender: news@comlab.ox.ac.uk
- Distribution: comp.lang.lisp
- Organization: Robotics Research Group, Engineering Science Dept, Oxford, UK.
- Lines: 60
-
- Sorry if this is a naive question, but you all seem pretty
- knowledgeable:
-
- I'm trying to write a function for accessing data stored in slots of
- frames. The problem is that if no value is available from that slot,
- I want to go and execute a bit of user code attached to that slot.
- The basic function that I am using looks like this:
-
- (val '<frame-name> '<slot-name>)
-
- At the moment, the user code attached to the slot gets called with the
- symbol 'self' bound to the value of <frame-name>. This lets the user
- code get at values from other slots in the same frame by inserting
-
- ... (val self '<another-slot-name>) ...
-
- as part of the code. This is pretty horrible. What I would really
- like to do is to let the user refer to the other slot names in the
- frame as if they were locally bound variables: eg. you could do:
-
- (+ <slot-1> <slot-2>)
-
- as a valid part of the code.
-
- Does anyone have any great ideas on doing this? The following methods
- I have thought of, but are either no good or I don't know how to
- implement them:
-
- 1. A list of all of the slots present in a frame is available; the
- user code calling sequence could bind each slot name to the value of
- the (val ..) function called for that slot.
-
- -- Inefficient to say the least. In fact it gets more hideous
- the more you think about it.
-
- 2. Do some parsing on the user code, to work out which slots are
- needed, and just go and get them before executing the code.
-
- -- Doesn't strike me as a good idea.
-
- 3. Bind each of the slot names to a macro (macrolet ... ?) that then
- gets expanded to (val self '<slot-name>) upon execution.
-
- -- This is the one I like best, but there are two problems:
- a) The user-code function call is already constructed using the
- backquote - I'd have to expand macros within this.
- b) I don't know how to do it, or if it is possible
-
- Your help would be greatly appreciated on this.
-
- Thanks
-
- Gordon
-
- --------------------------
- gordon@robots.oxford.ac.uk
- Gordon Buxton
- Pembroke College
- Oxford OX1 1DW
- --------------------------
-