On page 9 of “Metaprogramming Elixir” I came across, I think, an error. I thought for a long time whether to write about it or not, but I found a repetition of the same controversial idea in another author. Decided I needed to clear the matter up to the end.
Chris McArdv verbally describes the AST recursive structure:
"All Elixir code is represented as a series of three-element tuples with
the following format:
- The first element is an atom denoting the function call, or another tuple,
representing a nested node in the AST. - The second element represents metadata about the expression.
- The third element is a list of arguments for the function call."
Here the author builds a recursive link in the complex AST through the first element, which cannot be: the recursive link is implemented in the third element.
This is easy to check in iex:
quote do 1 + 2 * 3 end
{:+, [context: Elixir, import: Kernel], [1,
{:*, [context: Elixir, import: Kernel], [2, 3]}]}