When calling macros, when does one expect the AST to have as the first element :__block__?

When calling macros, when does one expect the AST to have as the first element :__block__?

Here is one example:

iex> quote do: (a; b) 
{:__block__, [], [{:a, [], Elixir}, {:b, [], Elixir}]}

You might find this post interesting too.

1 Like

But what is it about that incantation that leads to :__block__ being the first element of the AST? Or maybe a better way to ask would be "what does :__block__ mean in this context?

Any time two or more expressions are grouped together they are wrapped in a block. For example, in a do block if there is more than one expression:

iex> quote do
...>   if true do
...>     one()
...>     two()
...>   end
...> end
{:if, [context: Elixir, import: Kernel],
 [true, [do: {:__block__, [], [{:one, [], []}, {:two, [], []}]}]]}

And wrapping in parenthesis also introduces a block (similar to the earlier example):

iex> quote do               
...>   (     
...>     one()
...>     two()
...>   )
...> end
{:__block__, [], [{:one, [], []}, {:two, [], []}]}
5 Likes

That’s much clearer now. Thank you!