Elixir v1.0.5 Macro.Env

A struct that holds compile time environment information.

The current environment can be accessed at any time as __ENV__. Inside macros, the caller environment can be accessed as __CALLER__.

An instance of Macro.Env must not be modified by hand. If you need to create a custom environment to pass to Code.eval_quoted/3, use the following trick:

def make_custom_env do
  import SomeModule, only: [some_function: 2]
  alias A.B.C
  __ENV__
end

You may then call make_custom_env() to get a struct with the desired imports and aliases included.

It contains the following fields:

  • module - the current module name
  • file - the current file name as a binary
  • line - the current line as an integer
  • function - a tuple as {atom, integer}, where the first element is the function name and the seconds its arity; returns nil if not inside a function
  • context - the context of the environment; it can be nil (default context), inside a guard or inside an assign
  • aliases - a list of two item tuples, where the first item is the aliased name and the second the actual name
  • requires - the list of required modules
  • functions - a list of functions imported from each module
  • macros - a list of macros imported from each module
  • macro_aliases - a list of aliases defined inside the current macro
  • context_modules - a list of modules defined in the current context
  • vars - a list keeping all defined variables as {var, context}
  • export_vars - a list keeping all variables to be exported in a construct (may be nil)
  • lexical_tracker - PID of the lexical tracker which is responsible to keep user info
  • local - the module to expand local functions to

Summary

Functions

Returns whether the compilation environment is currently inside a guard

Returns whether the compilation environment is currently inside a match clause

Returns a keyword list containing the file and line information as keys

Returns the environment stacktrace

Types

aliases :: [{module, module}]
context :: :match | :guard | nil
context_modules :: [module]
export_vars :: vars | nil
file :: binary
functions :: [{module, [name_arity]}]
line :: non_neg_integer
local :: atom | nil
macro_aliases :: [{module, {integer, module}}]
macros :: [{module, [name_arity]}]
name_arity :: {atom, arity}
requires :: [module]
t :: %Macro.Env{module: atom, file: file, line: line, function: name_arity | nil, context: context, requires: requires, aliases: aliases, functions: functions, macros: macros, macro_aliases: aliases, context_modules: context_modules, vars: vars, export_vars: export_vars, lexical_tracker: lexical_tracker, local: local}
vars :: [{atom, atom | non_neg_integer}]

Functions

in_guard?(arg1)

Returns whether the compilation environment is currently inside a guard.

in_match?(arg1)

Returns whether the compilation environment is currently inside a match clause.

location(arg1)

Returns a keyword list containing the file and line information as keys.

stacktrace(env)

Returns the environment stacktrace.