https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/file/stat.ex#L55-L58
I came across above lines of code in the elixir code base. It would seem these variables were defined at module level and used from functions within the module.
I thought we could only do this with @constants :
Website for Elixir
The temporary-storage documentation does not make it clear either that such module level variables are permited.
Could this usage be documented better?
5 Likes
Linuus
February 14, 2017, 11:46am
2
I believe those are run at compile time and can only be used in macros.
1 Like
if you refer to the source code, they were used in functions
1 Like
Linuus
February 14, 2017, 12:42pm
4
Where?
In the code that you linked, you have this:
def to_record(%File.Stat{unquote_splicing(pairs)}) do
{:file_info, unquote_splicing(vals)}
end
unquote_splicing
is run at compile time.
See: http://elixir-lang.org/getting-started/meta/quote-and-unquote.html
2 Likes