Macros can create functions in the global scope, for example:
(defmacro test- Macro (& body functions) `(progn, @) (loop for functions in functions gather loop) (defun, function) * some interesting thing *)))
Another example (though with methods) will be automatically generated accessories for the CLOS class.
Function macro expansions are not defined at the time, but when the generated code is compiled / interpreted, there may be some difficulty if these actions are expected, then a warning will be thrown. What is idiotic way to define these actions before being properly defined? A possible solution may be the following:
(defmacro test-macro (& body functions) (macrolate ((empty-work (name) `(defun, name ()))) (Function functions) (Function functions)) (), (Loop for functions in functions) (deactivate, Function (some *) * Some interesting things *))))
Note that the intermediate function is defined during the macro expansion period.
If you need to define a function to compile at the above time, then use it:
(eval-when (: compilation-up) (defun foo ...))
Note that you can define such a macro Which generates such code. Such a form can be a part of a PROGN
.
No comments:
Post a Comment