Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Anonymous Macros

34 views
Skip to first unread message

Kenneth Liu

unread,
Feb 16, 1999, 3:00:00 AM2/16/99
to
Does anyone konw of a Lisp construct that would allow you to define
anonymous macros, sort of like LAMBDA, but for macros?

thanks

k

Barry Margolin

unread,
Feb 16, 1999, 3:00:00 AM2/16/99
to
In article <7acop9$lrl$1...@news.fas.harvard.edu>,

Kenneth Liu <ky...@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, bar...@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

unread,
Feb 16, 1999, 3:00:00 AM2/16/99
to
Barry Margolin <bar...@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

Kent M Pitman

unread,
Feb 17, 1999, 3:00:00 AM2/17/99
to
Kenneth Liu <ky...@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.

Barry Margolin

unread,
Feb 17, 1999, 3:00:00 AM2/17/99
to
In article <7acrcb$o4a$1...@news.fas.harvard.edu>,

Because macros operate on the original program text. Run time is too late
for a macro to do anything useful.

0 new messages