[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: macros vs. blocks

For those who haven't already seen it, Oleg Kiselyov gives a good summary of
the case for macros in this presentation:

One point he makes is that macros do not supplant "second-class objects":

"One sometimes hears that higher-order functions (and related
non-strictness) make macros unnecessary.  For example, in Haskell, 'if' is a
regular function.  However, every language with more syntax than
lambda-calculus has phrases that are not expressions.  Examples of such
second-class forms are: type, module, fixity and other _declarations_;
binding forms; statements.  Only macros can expand into a second-class
object.  The result of a function is limited to an expression or value."

The paper also gives the example of SSAX, a very powerful SAX parser
framework.  This uses a top-level macro, SSAX:make-parser, which builds a
parser based on user-provided callbacks.  This is described here:

The actively anti-macro camp might find useful material in this
presentation, since it points out some of the dangers of macros.  It also
proposes a solution, which is to use CPS to make macros composable, and also
to translate ordinary functions into macros so that CPS macros don't have to
be hand-written.  IOW, Oleg is writing functions which are "compiled" to CPS
macros, thus creating a domain-specific little language without having to
actually write macros.