Sorry, when I said AST, I meant the code that gets executed. A macro, at least the way I think about it, is inserting the resulting Expr into the main AST.
My macro's primary role is to create a dictionary mapping symbols to `Node`s. Each Node has an associated action (passed in with the curly braces). The actions themselves are `Expr`s, which need to be encapsulated as functions. I was hoping initially that the `Expr` for the action could be converted inline with the creation of the `Node`, as it would save the need of a lot of book keeping. Thus, the: `rule.action = insert_action_expr(expr.args[2])`. Another solution might to do two passes, where in the second pass the rule's `Expr`s are converted. Unfortunately, that seems less elegant than being able to convert an `Expr` to a function. On Sunday, March 22, 2015 at 9:39:30 AM UTC-4, Toivo Henningsson wrote: > > Maybe there is a confusion of terms here? An Expr is the way to represent > an AST in Julia (some very simple ASTs are instead represented by > ints/floats/strings/symbols). So when you talk about inserting an Expr into > an AST it seems to me that all it means is to make an Expr where some > subtree is given by another Expr. > > Macros are really only a way to save typing. Consider a few cases: what is > the input AST, and what is the output AST that you want to generate in each > case. From there, you should be able to figure out how to write the code > that does the transformation.