Module level variables - undocumented usage?

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:

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

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

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