Macro.expand/2 - why only one step?

iex(25)> quote do
...(25)> 1 |> rem(2) |> div(4)
...(25)> end |>
...(25)> Macro.expand(__ENV__) |>
...(25)> Macro.to_string
"div(1 |> rem(2), 4)"

Could you please tell me why this doesn’t expand further? Even further calls of Macro.expand/2 will not do that.

Is this to do with how iex works…?

Thank you!

1 Like

This function does not traverse the AST, only the root node is expanded.

https://hexdocs.pm/elixir/Macro.html#expand_once/2

2 Likes

So, how would one traverse the AST instead?

With the prewalk and postwalk functions?