Kernel.SpecialForms.require
You're seeing just the macro
require
, go back to Kernel.SpecialForms module for more information.
Requires a module in order to use its macros.
Examples
Public functions in modules are globally available, but in order to use macros, you need to opt-in by requiring the module they are defined in.
Let's suppose you created your own if/2
implementation in the module
MyMacros
. If you want to invoke it, you need to first explicitly
require the MyMacros
:
defmodule Math do
require MyMacros
MyMacros.if do_something, it_works
end
An attempt to call a macro that was not loaded will raise an error.
Alias shortcut
require/2
also accepts :as
as an option so it automatically sets
up an alias. Please check alias/2
for more information.