O'Reilly logo

Metaprogramming Elixir by Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required