Macros

A macro is a special form that translates its code into new code. That is, instead of performing the desired computation, the macro produces new code that performs the computation. A macro thereby provides a way of extending a language.

In Lisp, we can think of a macro call as being like a function call that is evaluated twice:

  1. The function that implements the macro is called, producing Lisp code as its value.

  2. That Lisp code is evaluated to produce the result.

A macro is defined using the form: (This form is used by DrScheme. Other versions of Scheme use different forms.)
(define-macro name
      (lambda (arguments ) code ))

A macro definition looks like an ordinary function definition, but the value returned by the macro is Lisp code to do what is wanted.

Contents    Page-10    Prev    Next    Page+10    Index