Further Exploration

We’ve unlocked the secrets of the abstract syntax tree that underlies all the Elixir code you write. Through quoting expressions, manipulating ASTs, and defining macros, you’re well on your way to advanced metaprogramming. In the coming chapter, we’ll be building more advanced macros to create custom language constructs, and we’ll write a mini testing framework that can infer meaning about Elixir expressions.

On your own, try expanding on the topics we covered. Here are a couple of ideas to get you started:

  • Define an unless macro without depending on Kernel.if, by using other constructs in Elixir for control flow.

  • Define a macro that returns a raw AST that you’ve written by hand, instead of using quote for code generation. ...

Get Metaprogramming Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.