Bending the Rules
Let's explore some gray areas where misusing macros in Elixir is a worthy trade-off.
Let’s take a moment to appreciate that Elixir makes the world our playground. Rules are made to be broken! So, here are some ways to misapply macros in Elixir and some interesting ways to bend Elixir’s syntax.
Misusing valid Elixir syntax
Rewriting the AST to change the meaning of valid Elixir expressions probably sounds wrong to most people. In some cases, it’s actually a powerful tool. Consider Elixir’s Ecto2 library, which is a database wrapper and Language Integrated Query system.
Let’s take a look at what an Ecto query looks like to understand how it misuses Elixir’s syntax. We don’t have to be familiar with Ecto, so just be mindful of the query syntax in the following example:
query = from user in User,
where: user.age > 21 and user.enrolled == true,
select: user
Internally, Ecto converts ...