Common Lisp the Language, 2nd Edition

Next: Compiler Macros Up: Macros Previous: Macro Expansion

# 8.3. Destructuring

X3J13 voted in March 1989 (DESTRUCTURING-BIND) to make the destructuring feature of `defmacro` available as a separate facility.

[Macro]

    destructuring-bind lambda-list expression {declaration}* {form}*

This macro binds the variables specified in lambda-list to the corresponding values in the tree structure resulting from evaluating the expression, then executes the forms as an implicit `progn`.

A `destructuring-bind` lambda-list may contain the lambda-list keywords `&optional`, `&rest`, `&key`, `&allow-other-keys`, and `&aux`; `&body` and `&whole` may also be used as they are in `defmacro`, but `&environment` may not be used. Nested and dotted lambda-lists are also permitted as for `defmacro`. The idea is that a `destructuring-bind` lambda-list has the same format as inner levels of a `defmacro` lambda-list.

If the result of evaluating the expression does not match the destructuring pattern, an error should be signaled.