In elixir modules are usually written as
defmodule Foo. The
is just sugar for the atom
:'Elixir.Foo'. The two are equlivelent. In the
true is just sugar for the atom
Module names in Erlang and Elixir are atoms. Elixir uses the upper-case convention to namespace Elixir modules. It is a very good idea to follow this convention. But what tricks could we do if we don't follow?
First question: if module names are atoms, and if
true is an atom, does that
mean we can name a module
try it out:
defmodule :true do
def x, do: true
iex> (not false).x
iex> (7 > 3) .x
iex> true and :ok
Well, not only can we define a module
true, but the module coexists
alongside the exising boolean interpretation. Boolean operators within the language
treat it as a boolean, but the dot operator treats it as a module name.
So that's it, we are free to use
to write some obscure code. I must admit I am impressed with how well the language handled my abuse.