I've seen a number of pieces of code around that define variables directly inside of a module, like
defmodule Example do
example = SomeModule.do_something()
end
I've been unable to find any explanation of this syntax in any documentation, though. I thought this might be useful for something I wanted to do and tried to make use of it, but it wouldn't let me call a function in the same module from there:
defmodule Example do
defp something() do ... end
example = something() # Error.
example = __MODULE__.something() # Also an error.
end
I wound up writing a macro in a separate module instead and that was able to do what I wanted, namely parse a file at compile-time and store the data pulled from it for later use, but how do these variables work? Why couldn't I call that function? Would I have been able to if it was defined in a different module because of oddities with compilation ordering? What can I do with these variables? How do I access the value stored in them?