Lisp macros

Lisp’s uniform, parenthesized syntax works especially well with macros. Languages of the Lisp family, such as Common Lisp and Scheme, have powerful macro systems because the syntax is simple enough to be parsed easily. Lisp macros transform the program structure itself, with the full language available to express such transformations. Common Lisp and Scheme differ in their macro systems: Scheme’s is based on pattern matching, while Common Lisp macros are functions that explicitly construct sections of the program.

Being able to choose the order of evaluation (see lazy evaluation and non-strict functions) enables the creation of new syntactic constructs (e.g. control structures) indistinguishable from those built into the language. For instance, in a Lisp dialect that has cond but lacks if, it is possible to define the latter in terms of the former using macros.

Macros also make it possible to define data languages that are immediately compiled into code, which means that constructs such as state machines can be implemented in a way that is both natural and efficient.

— Wikipedia on Macro (computer science)

2010.03.30 Tuesday ACHK