Hello everybody.
Another day, another proposal 😅
The problem:
A lot of macros, when called, need to define a function - be it a private, helper function, or a final public function. This is very easy, when the macro is top-level (called directly in the module body). Unfortunately it's much harder to do, when the macro is called inside a function.
Currently, there are two solutions:
1. Register a before_compile hook and accumulate data in some module attribute
2. Use Module.eval_quoted.
Both solutions are rather ugly, possibly slow (especially in case of eval) and can lead to a very hard-to-debug code.
Solution:
I propose adding a Macro.define/3 function, that would allow to add a function or macro to a module under compilation, from any place. This way, the solution is obvious, does not require using any kind of eval and is local (unlike the module attribute solution proposed above).