4 ms·
Tip: the first move when trying to write a macro is doing `Meta.@dump` on examples of argument expressions you want your macro to consume and produce. Then writ
by StefanKarpinski 5y ago
Tip: the first move when trying to write a macro is doing `Meta.@dump` on examples of argument expressions you want your macro to consume and produce. Then write code that transforms the inputs to the outputs.
- dan-robertson 5y agoRight but it wasn’t obvious to me (at the time) what a change to the source code would do to the ast, so it wasn’t easy to know all the cases to handle, especially with quasiquotation (I think double-backtick style programming was basically impossible). For example, maybe you want to handle something that looks like: foo ~~> bar In lisp syntax (and recall that is what the Julia ast is: everything is a head and then arguments) it might look like: (~~> foo bar) ; or (op ~~> foo bar) But if you change to e.g. foo ~~> bar + 5 You might get (+ (~~> foo bar) 5) Or (~~> foo (progn (+ bar 5))) I don’t remember what you got or which cases were tricky, only that I could never guess what the output of dump would be.