In article <············@news.fas.harvard.edu>,
Kenneth Liu <·····@fas.harvard.edu> wrote:
>Does anyone konw of a Lisp construct that would allow you to define
>anonymous macros, sort of like LAMBDA, but for macros?
No. How would you use it?
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.
Barry Margolin <······@bbnplanet.com> wrote:
> No. How would you use it?
I haven't really thought this through, so this is really just a "what-if"
kind of question. Since there's DEFUN and DEFMACRO, FLET and MACROLET, I
just thought what if we pushed the parallel further and got something like
LAMBDA, for macros.
Come to think of it, I guess the question really still goes back to why
you can't APPLY macros (if you can do that, then I can see some
places where you would construct an anonymous macro at run time and
"apply" it)
thanks
k
In article <············@news.fas.harvard.edu>,
Kenneth Liu <·····@fas.harvard.edu> wrote:
>Barry Margolin <······@bbnplanet.com> wrote:
>
>> No. How would you use it?
>
>
>I haven't really thought this through, so this is really just a "what-if"
>kind of question. Since there's DEFUN and DEFMACRO, FLET and MACROLET, I
>just thought what if we pushed the parallel further and got something like
>LAMBDA, for macros.
>
>Come to think of it, I guess the question really still goes back to why
>you can't APPLY macros (if you can do that, then I can see some
>places where you would construct an anonymous macro at run time and
>"apply" it)
Because macros operate on the original program text. Run time is too late
for a macro to do anything useful.
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.
Kenneth Liu <·····@fas.harvard.edu> writes:
> Does anyone konw of a Lisp construct that would allow you to define
> anonymous macros, sort of like LAMBDA, but for macros?
I usually use MACROLET.
(MACROLET ((DO-IT ()
...))
(DO-IT))
But I suppose you could just do:
(DEFMACRO META (&REST FORMS)
(LET ((DO-IT (GENSYM "DO-IT")))
`(MACROLET ((,DO-IT () ,@FORMS))
(,DO-IT))))
Also, of course, a lot of people just use #. for this kind of thing.
It doesn't do the same thing semantically, but its set of potential
uses overlaps.
FWIW, the total number of times I have ever wanted this in my career
is approximately five; if others' experiences are similar (and I
suspect most people do it even less) that is probably why it's not in
the language. But that doesn't mean it's an unreasonable thing for
someone to wish for. The usual place I actually resort to this is in
dealing with a set of computable forms that is large to type in or
requires some thought to compute and where the form to compute it is
more instructive than the actual value, and where the thing I'm
dealing with is conceptually a constant. For example, a table of the
first 30 primes or a table of the alphabetic successors of each letter
(e.g., A=>B, B=>C, C=>D, etc.). Sometimes there are also cases where
you actually can't know the text to write because it's
implementation-dependent.