[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- To: (BUG LISP) at MIT-ML
- Subject:
- From: RIVEST@MIT-ML
- Date: Tue, 30 Jan 80 14:55:41 GMT
- Original-date: 01/30/80 10:55:41 EDT
Second the suggestion. I think backquote needs to be extended. Consider the
following problem: I want to define a macro SETPROP so that (SETPROP x y z)
does two things: a (PUTPROP x y z) and also it defines a macro for z so that
(z foo) will extract foo's z property. My first attempt was something like:
(defmacro setprop (x y z)
`(prog2 (putprop ,x ,y ,z)
(defmacro ,z (v) `(get ,v ',z))))
This almost works, except that the commas in the nested backquote are at
different levels. The first-level expansion of the macro call (SETPROP
'a 'b 'c) tries to expand v.
Nope! (Boy am I a little confused!) I just tried that and discovered that
thhe problem is that Z is undefined when the defmacro for C is evaluated.
So I guess the rule is that in the evaluation of a back-quoted form, only
those comma-expressions are evaluated and plugged in which are not themselves
inside further nested backquoted forms. (please explain this clearly somewhere
in the documentation !)
So how do I get what I want (elegantly, of course)? Some way of
associating commas with backquotes seems a useful possibility. In the
above example, we want Z to be evaluated and plugged in when the outer
backquoted form is evaluated.
Let me suggest the following extension: let a series of k commas
associate that comma with the k-th backquote, working outwards from the
occurence of the commas. Thus one comma works as before, and I get what
I want with:
(defmacro setprop (x y z)
`(prog2 (putprop ,x ,y ,z)
(defmacro ,z(v) `(get ,v ',,z))))
So the Z is evaluated with the outer backquoted form. This generalizes
to ,@ etc.
Comments?
Ron Rivest