XLISP macroexpand-1

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# macroexpand-1

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

## Syntax

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

## Description

The 'macroexpand-1' function takes a 'form' and expands the first level of the macro definition 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)
    (macroexpand-1 '(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-1', 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-1' for the environment of the expansion. XLISP does not support this optional argument.

See the macroexpand-1 function in the XLISP 2.0 manual.

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference