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

Bending the Rules

That’s the offical warning over with. So let’s take a moment to remember that Elixir makes the world our playground. Rules are made to be broken. So here are some gray areas where abusing macros in Elixir is a worthy tradeoff, and some interesting ways we can bend Elixir’s syntax.

Abusing Valid Elixir Syntax

Rewriting the AST to change the meaning of valid Elixir expressions probably sounds evil to most people. In some cases, it’s actually a powerful tool. Consider Elixir’s Ecto[11] library, which is a database wrapper and Language Integrated Query system. Let’s take a look at what an Ecto query looks like to see how it abuses Elixir’s syntax. You don’t have to be familiar with Ecto; just be mindful of the query syntax in the ...

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