📎 Webclip
Macro See, Macro Do
The post traces how Phoenix uses quote/2 to package code as AST and how use expands into a call to __using__/1. It uses a small example to show that the shared import and alias setup can be generated instead of written by hand.
Reading notes#
quote/2appears in Phoenix code that sets up controllers with shared imports and aliases.- A simple
Bar.AllTheThingsexample reproduces that pattern withquote do ... end. use Bar.AllTheThings, :thingsfails until__using__/1is defined.__using__/1calls the named function throughapply/3.quote do sum(2, 2) endreturns AST as a three-element tuple.import Bar.Mathalso has an AST form with:importand alias metadata.- The same AST can be written directly without
quote/2. use Bar.AllTheThings, :thingsexpands toBar.AllTheThings.__using__(:things).- The post concludes that
quoteconverts Elixir code to AST and supports dependency injection through macros.
