From: Tim Bradshaw
Subject: Anti-pretty
Date: 
Message-ID: <ey3y9uhmzz0.fsf@cley.com>
There is periodic discussion here about whether or not macros should
be like CL's -- exposing the whole power of the language but requiring
programmer competence -- or like those in some other languages -- less
powerful but somehow `more pure'.  Here's why I think CL is right.

Like everyone else, I have a macro which essentially compiles a Lispy
representation of HTML into Lisp code which will print the equivalent
at runtime.  You can intersperse ordinary Lisp with this, so things
like

        (:ul
          (loop repeat 10 do
            (htm ((:a :href "/") "Go home"))))

Work in the obvious way.

Of course quite a lot of these lispy HTML expressions are compile-time
constants.  So my macro keeps track of the constantness of things when
it's compiling (it just looks for interpersed Lisp code), and if the
whole form is a constant, it then evals it at macro-expansion time,
and generates code that is basically a single call to WRITE-SEQUENCE
of a literal string. Things work such that in the above sample the
inner HTM calls actually get compiled to a constant even though the
main expression is not detected as such.

To do this it uses a special variable as the constantness flag, and
calls EVAL at macro-expansion time.

I think it's really hard to see how you would do this without CL-style
macros, or something close to them, and it's just a great expression
of all the things CL does right that you can do this stuff entirely
within the standard language.

--tim
From: David Bakhash
Subject: Re: Anti-pretty
Date: 
Message-ID: <m3wva0llkg.fsf@alum.mit.edu>
Tim Bradshaw <ยทยทยท@cley.com> writes:

> Of course quite a lot of these lispy HTML expressions are
> compile-time constants.

Yes.  Also, DEFINE-COMPILER-MACRO allows the ability to treat
functions differently at compile-time than at run-time, and since you
have the full power of CL at compile-time to examine and manipulate
data, you can certainly use the macro and compiler-macro system in the 
compiler environment to optimize code.

I believe that this is how ACL's primary regexp function works.  If
they wanted a lispy syntax for regexps instead of the string-based one 
common nowadays, they could use macros similarly to the way you did.
Even if they couldn't get the thing to be constant, they could
partially compile the regexp into some kind of canonical format which, 
at run-time, compiles much faster, so you get to write it in the most
convenient way, but *your* compiler still gets to rewrite it before
that ever happens.

dave