| A rough equation: Macro = Language level customization (for example, you want to mix two different languages, like HTML + Java or Java + SQL etc and still make the resulting code very readable vs using quoted strings all over the place) Think of frameworks or code generators. (Assuming familiarity with Java) Consider a JSP page, and contrast it to the Java servlet that a JSP page generates. JSP allows you to embed Java fragments in a HTML file. A Java compiler cannot by itself read it, so a JSP pre-compiler takes it, generates Java servlet code out of it. That servlet code has HTML strings embedded in it all over the place, so is hard to read, hard to maintain, and hard to write in the first place. The JSP solution allows you to separate the visual design part (HTML/CSS) from the Java part.The pre-compiler generates normal Java code from this Java-embedded-HTML. This is a classic macro solution. In Lisp, unlike Java, the macro code generation facility is built-in. This is both a plus and a minus. You don't do Lisp-embedded-in-HTML, but you would do Lisp-made-to-look-sort-of-like-HTML. A well-designed macro like that would make code easier to understand than traditional non-macro code which will have HTML fragments embedded as strings all over the place. I personally prefer code generators to macros, because when you want that linguistic convenience, you really want it (I want full HTML/CSS, not someone's bastardized macro that kind of looks like HTML). Thinking in terms of code generators also keeps macro-abuse minimal, simply because you have to work a bit harder to do code generation. A lot of Lisp macros are really mental masturbation by show-off artists. |