How I learned to stop worrying and love macros
summary
Explains exactly how Elixir macros generate real code: use of __using__ to inject functions, quote/unquote and unquote_splicing to build AST, and before_compile plus module attributes to collect rules then emit final functions. Shows decoding generated bytecode from Gettext to inspect the compiled functions, compares macro generation with EEx template codegen, and demos a firewall DSL that compiles CIDR/range rules into pattern-matched functions. Advises sparing use, notes macros speed runtime and reduce duplication but can obscure debugging.
AI-written summary · about
chapters (13)
- 0:00Introduction to macros
- 1:21Why use meta programming
- 5:23Macros and code generation
- 12:37Using macros in practice
- 17:37Detecting and defining functions
- 23:29Before compile hooks
- 26:19Overusing macros
- 28:04Code generation with EEx
- 29:30Debugging generated code
- 36:07Splitting implementations across files
- 39:40Macros and maintenance
- 44:20DSLs with macros
- 56:51Wrap up and resources
related talks
52mWrite Less, Do More (and Have Fun!) with Elixir Macros
37mMetaprogramming + DSL Design in Elixir
51mPipe Dreams - Getting More out of Elixir Pipes
22mRefactoring Elixir for maintainability
56mKeynote: Think Different
40mExecutable Contracts for Elixir
32mElixir for the rubyist
49mKeynote: How to sell Elixir (Again)
