I got some help solving this question on stackoverflow, not that I intend to use complicated pipelines in every day programming.
What I realized that I’ve some learning to do in reading Elixir expressions and understanding how they are evaluated.
Is there some tool that can take an Elixir expression and print out some kind of graphic tree of how it is evaluated? If not then something in text that is easier to understand.
Does iex have a tool that can output something like that? I know Elixir syntax is considered easy to understand, but being more familiar with procedural languages where code is more explicit I need all the help in the beginning.
If you Google “display code parse tree” and click on Images you will see a number of pictures demonstrating the idea. It doesn’t have to be actually graphical, but should display how the expressions are broken down for evaluation.
It should break down each function into a tree showing the function at the root and the parameters (which may be other function calls) at the leaves,
What you see is a nested list of 3-tuples. The first elem is an identifier, the second elem is metadata, and the third elem contains the tuples from deeper in the tree.
“the context and import” items in the metadata are hints to the compiler about where to look up the symbols found in the tree. In this case we’re in the context of the Elixir programming language. From most of what I know… the metadata is not documented anywhere but by-in-large you can ignore it.
I this case you end up with a simple parse tree …
You can assume that items lower in the tree will be evaluated before those higher up. So the first evaluation is to look up the value of a, then look up the value of b, then call the function Kernel.+ with those two arguments.
I like to read the final generated end-point code of erlang via Core. The EVM/BEAM uses a base-most syntax called Core, kind of a mini-erlang language, very easy to use and parse and all. I’m unsure how to output core from Elixir code without calling in to the low level compiling primitives and passing that output to the erlang core compiler pass (which I’ve done), but it would be nice if someone PR’s a --core option to elixirc to do that more easily.