Macros are one of those items that are conceptually simple but hard to read and utilize in practice.
Each piece is simple in isolation. Macros are special functions that receive an AST and return an AST. quote/2 turns an expression into an AST. unquote/1 evaluates an expression and injects the results into a quoted expression (a.k.a. an AST fragment). And of course you have the concept of “hygiene” - variables created in a macro are private to that macro unless explicitly defined otherwise.
So again, the pieces are, on their own, easy to wrap your head around, but putting them together I’ve found difficult.
There are two great resources out there for learning Elixir’s metaprogramming capabilities - @chrismccord’s Metaprogramming Elixir and @sasajuric’s Understanding Elixir Macros mini-series. Head still hurts, and it will probably take two readings of each to have macros really sink in for me. (Oh, and of course the documentation on quote/2 is incredible).
I’m not sure what the point of my post is/was now. ![]()






















