Prior to this commit, the following code would work:
defmodule Hello do
defmacro write do
quote do
a = 1
end
end
defmacro read do
quote do
a
end
end
end
require Hello
Hello.write
Hello.read
Although this is convenient, it has many issues:
1. It is not clear at any point the intent of sharing the variables
in between the macros
2. Whenever macros from the same module are nested, there is a chance
a variable used before and after the nesting to be overriden
We address this issue by only allowing variables explicitly marked
with var! to be shared. Here is how the example above should be updated:
defmodule Hello do
defmacro write do
quote do
var!(a, Hello) = 1
end
end
defmacro read do
quote do
var!(a, Hello)
end
end
end
require Hello
Hello.write
Hello.read