Your Turn
Elixir macros are a rarely used but important feature. They’re used to write both Elixir code and beautiful APIs called domain specific languages.
Macros
Underneath, Elixir code is represented within the abstract syntax tree, or AST. A macro is code that writes code. Macros take a bit of the AST and translate it into other ASTs. The quote function lets developers convert Elixir code into the AST format, and the unquote function allows interpolation of Elixir code. Together, they can make existing Elixir code do new and interesting things.
A DSL is a domain specific language. While Elixir is a general-purpose programming language, a DSL uses the features of Elixir, especially macros, to represent other concepts. For example, the Ecto ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access