Pregunta

I understand that destructuring in LISP macro parameters is a nice thing to have; I am wondering whether it is essential. As an example,

(defmacro m1 (a) (car a))

and

(defmacro m2 ((a1 a2)) a1)

seem to be (roughly) equivalent - except for checking for the right form of the parameter(s).

My guess is that destructuring makes the code easier to write/understand, but any code using it may be translated into one that does not. Am I right or is this a stupid beginner's mistake?

¿Fue útil?

Solución

It is not essential. You can either let the macro call be destructured by the Lisp system or you write your own code for that inside the macro.

If you would write your own destructuring code you would combine it usually with a &rest or &body parameter list. One usual reason for that is also that the syntax possibilities of the macro lambda list is not flexible enough for a certain purpose. An example for that would be the Common Lisp LOOP macro.

It is good style to use the macro lambda list. It provides an interface with parameters and some structure information. This also allows the Lisp system to provide a simple form of syntactic error checking of macro calls. Something one would have to write by hand.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top