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