Is there a way to make a submodule "open"

In this case I think it’ll come down to the detail of how you plan to use it (managing the state and utility functions as you said) so the choice can’t be made without those details. It’s nice to see the concrete use case :+1:

Yes macros are exactly user-defined syntactic sugar. In the compiler, the first part of code lowering after macro expansion is to deal with all the built in syntactic sugar. The code which does this functions exactly like a macro expander (just working on built-in Expr heads rather than Expr(:macrocall)).

When designing complex macro-based interfaces I find it’s extremely useful to write out the code you want the macro to generate by hand to check that the implementation works. When it works for a couple of test cases, then try to write the actual macro. One way this helps is to separate the code which must be generated from any utility functions which the generated code can call.

4 Likes