Is there any way to get ASTs' free vars and bound names when performing macros?

@mymacro function (arg1, arg2)
     bound1 = arg1 +  arg2
     bound2 = bound1 + closure1

Is there any builtin tool to supply this sort of analysis?

Check out MacroTools.jl

1 Like

Which sort of analysis?

No, there is not. Julia figures this type of information (free and bound names) out after the macro expansion pass. All you have is what dump shows is in the AST. However, once you parsed the function header (preferably using MacroTools) you can do it yourself.

Good reads:,

1 Like

At least I want to get the variable names inside an AST and group them into bound names and free vars. It could be better if any type inference there.

Yes, postwalk in MacroTools.jl could work but it’s still a heavy task to reach my goal from using MacroTools…

Did you see

Thanks, I do have checked it out, but only the function signature is not enough, bound names except arguments and free vars are from function body.
splitdef could extract the body for me and then I have to traverse it to get all of the variable names and group them into bound names and free vars.