Hi , I need clarification on how unquote works, I understand it’s needed to inject variables outside the quote context into the quote context, with string interpolation being used to hammer home this point.
Consider below simple macro.
defmacro clarify(expr) do
quote do
unquote(expr)
end
end
A macro receives an AST and returns an AST; this means the AST of expr
will be passed to the macro
Assuming 1 + 2 - 3
is pass, the AST will be
{:+, [context: Elixir, import: Kernel],
[{:+, [context: Elixir, import: Kernel], [1, 2]}, 3]}
- Will unquote convert/evaluate this AST to
1 + 2 - 3
- Or will it evaluate the expression to
0
- Both
- Will evaluate this AST to
1+ 2 - 3
, then the quote macro will convert it back to the AST which is returned and executed/evaluated.
Thank you.