As how I understand it, Julia parses and evaluates code piece by piece. Thus it is possible for a macro definition to access a variable’s runtime value when the macro is expanded. Whether or not it makes sense to read or write a variable’s value when a macro is expanded depends on the order in which the program is compiled. Does there exist such a specification about the ordering?
To give a few concrete examples of my confusion:
constglobal variables are bound to their value before any macro is expanded. Am I correct? I learned it from this question Macro for counting the number of times a function is called? and how Spark.jl defines
@attachbut I can’t yet find the documentation.
If I have some code like this:
a = some_function() @some_macro d = 1 + 2
@some_macro d = 1 + 2 is expanded, can it reliably access
a's runtime value (the value returned by
- If I import a module to my program as
import SomeModule ...other code...
can I be sure that
SomeModule's global variables are bound and macros are expanded before any macro in
...other code... is expanded?