XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

macroexpand


Type:   -   function (subr)
Source:   -   xlbfun.c

Syntax

(macroexpand form)
form - a macro form
returns - the macro expansion

Description

The 'macroexpand' function takes a 'form' and recursively expands the macro definitions used in the 'form'. The function returns the expansion. If the 'form' does not contain a macro, the form is returned unaltered.

Examples

(defmacro plus (n1 n2) `(+ ,n1 ,n2))   ; define PLUS macro
(plus 1 2)                             ; returns 3
(macroexpand '(plus 3 4))              ; returns (+ 3 4)

(defmacro pl (p1 p2) `(plus ,p1 ,p2))  ; define PL macro using PLUS
(pl 3 4)                               ; returns 7
(macroexpand '(pl 3 4))                ; returns (+ 3 4)
(macroexpand-1 '(pl 3 4))              ; returns (PLUS 3 4)

Common Lisp: Common Lisp returns 2 values for its result of 'macroexpand', the expanded form and a  T  or NIL value that indicates if the form was a macro. XLISP returns only the expanded form. Common Lisp also supports an optional argument in 'macroexpand' for the environment of the expansion. XLISP does not support this optional argument.

See the macroexpand function in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next