The abstract syntax tree
You may have already heard about Abstract Syntax Trees (ASTs) in other languages. As the name indicates, these are tree-like data structures that represent the code syntax. In Elixir, we call these representations quoted expressions.
If we try to obtain the quoted expression of simple expressions, such as single atoms, strings, integers or floats, lists or two element tuples, we'll see their quoted representation doesn't change when compared to their normal representation. These elements are called literals because we get the same value after quoting them. Take a look at the following code:
iex> quote do: :"Funky.Atom" :"Funky.Atom" iex> quote do: ["a", "b", "c", "z"] ["a", "b", "c", "z"] iex> quote do: 1.88 1.88 iex> quote do: "really big string but still simple" "really big string but still simple" iex> {:elixir, :rocks} == quote do: {:elixir, :rocks} true
The tree form of the quoted expressions is created by nesting three-element tuples and can...