The scenario: I am writing a DSLish set of macros that create a few functions that again call code the user has provided verbatim (in the macro call), so something like this:
@mymacro Bla myfun1() myfun2() end
Which will create, say
Blafunc2 which again call
Now, all of this works quite nicely. However I find it extremely unsatisfying that my macro clutters the current module’s namespace with new functions with ugly names. My solution would be to let
@mymacro create a submodule (
Bla in this case) that contains the generated functions which I can then call as e.g.
All of that works save for one issue which is that I can’t find a general mechanism to make symbols from the surrounding module known within the newly generated module (
Bla). I can add a
import with the parent module name as argument to the generated module, however if the user-supplied functions haven’t been exported they will still not be visible.
So, my question is if there is any way to open the generated submodule’s scope to let it include all symbols in the parent module?
I can think of a few alternative solutions such as parsing the macro arguments for symbols and adding includes for all of them or requiring users to fully qualify all names, but none of them make me happy TBH.