--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/1eb41980-0e6d-4b6c-85df-a4933d4607d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
In order to build a variable, a context is expected.
Most of the times, in order to preserve hygiene, the
context must be __MODULE__:
iex> Macro.var(:foo, __MODULE__)
{:foo, [], __MODULE__}
However, if there is a need to access the user variable, nil can be given:
iex> Macro.var(:foo, nil)
{:foo, [], nil}I think the purpose of Macro.var(:x, nil) is to allow a variable bound in the macro (quoted block) to be accessible outside of the macro. For example, if your macro does something like
defmacro my_macro do
quote do
unquote(Macro.var(:foo, nil)) = :bar
end
end
Then the client code can access var foo:
my_macro
IO.inspect foo