Kernel.SpecialForms: Know the Environment and Limitations

Learn about what is and isn’t possible when extending the Elixir language.

Even though Elixir is an incredibly extensible language, it has areas that are special and not overridable. Knowing where these are and why they exist will help keep us grounded in what is and isn’t possible when extending the language. It will also help us keep track of where our code is executing.

The SpecialForms module

The Kernel.SpecialForms module defines a set of constructs that we can’t override. They make up the basic building blocks of the language and contain macros such as alias, case, {}, and <<>>. The SpecialForms module also includes several pseudo-variables, which contain information about the environment at compile time. Some of us might already be familiar with a couple of these variables, such as __MODULE__ and __DIR__. The following pseudo-variables are defined by SpecialForms and cannot be assigned to or overridden:

  • __ENV__: Returns a Macro.ENV struct containing current environment information
  • __MODULE__: Returns the current module name as an atom, equivalent to __ENV__.module
  • __DIR__: Returns the current directory
  • __CALLER__: Returns the caller’s environment information as a Macro.ENV struct

Get hands-on with 1400+ tech skills courses.