Dylan macros allow you to create new control constructs and other high-level forms. They can be used to automatically release resources, simplify class creation, or adapt Dylan for a specific problem domain.

Let’s say you find this code a little too verbose:

if (test())
  f1(many, arguments, here)
  long-function-name(and, more, args)

and you’d rather be able to write it this way:

    f1(many, arguments, here),
    long-function-name(and, more, args))

You can’t just define iff as a function because then the calls to both f1 and long-function-name will be evaluated. Instead, you can write a macro:

define macro iff
    { iff(?test:expression, ?true:expression, ?false:expression) }
 => { if (?test) ?true else ?false end }

See also: