4 ms·
You can always macroexpand a macro to know precisely how it's defined and it's going to be executed [1]. If you use emacs+slime it's as easy as putting your cur
by kroger 13y ago
You can always macroexpand a macro to know precisely how it's defined and it's going to be executed [1]. If you use emacs+slime it's as easy as putting your cursor before an expression and tying a keybinding [2].
But in the reality using macros is no more complicated than using functions.
[1] http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_macroexpa_acroexpand-1.html http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec...
[2] http://www.common-lisp.net/project/slime/doc/html/Macro_002dexpansion.html http://www.common-lisp.net/project/slime/doc/html/Macro_002d...
- catnaroek 13y ago> But in the reality using macros is no more complicated than using functions. Do I have any guarantee that the resulting macro-expanded code semantically makes sense? (e.g., a guarantee that it will typecheck)
- kroger 13y agoLisp macros receive as input valid s-expressions, that don't need necessarily to be valid common lisp code, such as (my-macro (2 + 2)) and output valid lisp code during macro expansion time. The macro my-macro could expand the code to something like: (+ 2 2) Some Lisp compilers such as CMUCL will issue a warning if you try to use wrong type (it has type inference), such as in this simple example: (defmacro foo () `(+ 1 "foo")) (defun bar () (foo)) You can see the compiler notes here: http://imgur.com/3vlQm6G http://imgur.com/3vlQm6G