[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
the uses of macros (Re: various recent ll1 threads)
At Sat, 25 May 2002 05:01:07 -0400 (EDT), Kragen Sitaker wrote:
> I thought I'd reply to recent LL1 traffic with one message instead of
> So you can go some distance in the direction of syntactic abstraction
> in Python with operator overloading. But I often wish for more, for a
> variety of reasons explained in _On Lisp_. Most often, I wish for
> unwind-protect macros (Scheme's with-open-file, for example, and
> sometimes I wish for an analogous with-lock-held) and new binding
> constructs, although I would like these to be merely a more convenient
> interface to existing functions.
I'd like to propose that there are three disciplined uses of macros:
1. data sublanguages: I can write simple looking expressions and
create complex nested lists/arrays/tables with quote, unquote etc
neatly dressed up with macros.
2. binding constructs: I can introduce new binding constructs with
macros. That helps me get rid of lambda's and with placing things
closer together that belong together. For example, one of our teachpacks
contains a form
(string-append "Hello " first-name " what's your last name?"])
... last-name ... first-name ...)
with the obvious interaction between a program and a Web consumer implied.
[Note: In ML you could write
web-query(fn last-name => ...)string_append(...)
but by golly that's a pain and an unnecessary pattern.]
3. evaluation reordering: I can introduce constructs that delay/postpone
the evaluation of expressions as needed. Think of loops, new conditionals,
[Note: In Haskell, you don't need that one.]
I understand that Lispers use macros for other reasons. In all honesty, I
believe that this is partly due to compiler deficiencies, and partly due to
"semantic" irregularities in the target language.
I challenge people to address all three issues when they say language X
can do what macros can do.